phalcon-devtools is the Phalcon Devtools command line tool (see References). Crest replaces it. The table gives the Crest command for each command of devtools v4. The aliases are in parentheses. The options are not the same: the section of each command gives its options.
| devtools v4 | Crest |
|---|---|
info (i) |
about (info, i); see Command reference |
commands (list, enumerate) |
list (commands, enumerate); see Command reference |
serve (server) |
serve (server); see Running a project |
project (create-project) |
new; see Creating a project |
controller (create-controller) |
make:controller; see Generating controllers |
model (create-model) |
make:model; see Generating models |
all-models (create-all-models) |
make:model --all; see All the tables |
module (create-module) |
make:module; see Generating modules |
scaffold (create-scaffold) |
make:scaffold; see Generating scaffolds |
migration (create-migration) |
vendor/bin/phalcon-migrations, the command of the package phalcon/migrations; see References |
console (shell, psysh) |
not in Crest 1.0. Install PsySH with composer require --dev psy/psysh. vendor/bin/psysh <file> loads <file> first, as console --include=<file> did |
webtools (create-webtools) |
none: Crest has no web interface |
A project of devtools. Crest writes each class with a namespace, and init needs a psr-4 entry in composer.json (see Adding Crest to an existing project). devtools wrote no composer.json: app/config/loader.php loads the classes with Phalcon\Loader. In a simple project of devtools, the classes have no namespace. Before you run init:
-
Add the psr-4 entry to
composer.json, for example"App\\": "app/". -
Give each class the namespace of its folder. With
"App\\": "app/", a class inapp/controllershas the namespaceApp\controllers. ForApp\Controllers, change the name of the folder toapp/Controllers. Amodulesproject of devtools has namespaces already: give each one a psr-4 entry. -
Phalcon finds a controller by its namespace. Set the namespace of the controllers with
setDefaultNamespace()of thedispatcherservice. -
Add a front controller for Crest.
make:modelandmake:scaffoldread thedbservice, so Crest starts the class of thebootstrapkey (see Commands that boot the project). A project of devtools has no such class:public/index.phpdefinesBASE_PATHandAPP_PATH, and includesapp/config/services.php, which registers thedbservice. This is the same in thesimple,microandmodulesprojects. Addapp/AppFront.php, which does the same and returns the container.public/index.phpdoes not change:<?php declare(strict_types=1); namespace App; use Phalcon\Di\DiInterface; use Phalcon\Di\FactoryDefault; final class AppFront { public function __construct(private string $root) { } public function boot(): DiInterface { defined('BASE_PATH') || define('BASE_PATH', $this->root); defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app'); $di = new FactoryDefault(); include APP_PATH . '/config/services.php'; return $di; } } -
Run
composer dump-autoload. -
Run
crest init. For the front controller,initproposesApp\AppFront. For the questions of the paths, give the folders of the project, for exampleapp/controllers,app/modelsandapp/views.
The models. A model of devtools has its properties. A model of Crest extends a base that has the properties, and Crest writes the base again each time you run make:model (see Generating models). Move each model with the steps of “Moving a devtools --get-set model” (see Getters and setters). For a model that devtools wrote without --get-set, keep 'getSet' => false in step 1: init writes it.
The Annotations strategy. With --annotate, devtools wrote the annotations @Column, @Primary and @Identity on the properties. A base of Crest has typed properties and no annotations. When the modelsMetadata service uses Phalcon\Mvc\Model\MetaData\Strategy\Annotations, Phalcon reads the columns from these annotations, and finds none. The C extension stops with this error:
No properties with annotations were found in class UsersDo one of these:
-
Change to the Introspection strategy, the default of Phalcon: remove the
setStrategy()call of themodelsMetadataservice. Phalcon then reads the columns from the database. -
Keep the Annotations strategy. In each model, declare each property of the base again, with the same visibility, type and default, and put the annotations on it. Crest writes a model one time (only
--forcereplaces it), so the annotations stay. When a column changes, change its annotation:class Users extends UsersBase { /** * @Primary * @Identity * @Column(column="id", type="integer", nullable=false) */ public ?int $id = null; }On
phalcon/phalcon, the Annotations strategy also needs the packagephalcon/annotations.