Skip to content

Moving from Devtools

Move a project from Phalcon Devtools to Crest: the Crest command for each devtools command, and the steps for the models.

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:

  1. Add the psr-4 entry to composer.json, for example "App\\": "app/".

  2. Give each class the namespace of its folder. With "App\\": "app/", a class in app/controllers has the namespace App\controllers. For App\Controllers, change the name of the folder to app/Controllers. A modules project of devtools has namespaces already: give each one a psr-4 entry.

  3. Phalcon finds a controller by its namespace. Set the namespace of the controllers with setDefaultNamespace() of the dispatcher service.

  4. Add a front controller for Crest. make:model and make:scaffold read the db service, so Crest starts the class of the bootstrap key (see Commands that boot the project). A project of devtools has no such class: public/index.php defines BASE_PATH and APP_PATH, and includes app/config/services.php, which registers the db service. This is the same in the simple, micro and modules projects. Add app/AppFront.php, which does the same and returns the container. public/index.php does 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;
        }
    }
  5. Run composer dump-autoload.

  6. Run crest init. For the front controller, init proposes App\AppFront. For the questions of the paths, give the folders of the project, for example app/controllers, app/models and app/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 Users

Do one of these:

  • Change to the Introspection strategy, the default of Phalcon: remove the setStrategy() call of the modelsMetadata service. 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 --force replaces 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 package phalcon/annotations.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close