Cphalcon: Controller lazy loading fails with error "Parameter 'definition' must be a string" when using Micro

Created on 29 Jun 2017  路  2Comments  路  Source: phalcon/cphalcon

Using lazy loading with Micro, Collection and Controller fails when bootstraping Phalcon with Micro.

/public/index.php

require __DIR__ . '/../bootstrap/bootstrap.php';

/bootstrap/bootstrap.php

use Phalcon\Mvc\Micro;

$app = new Micro();

require __DIR__ . '/../config/routes.php';

$app->handle();

/config/routes.php

use Phalcon\Mvc\Micro\Collection;

require __DIR__ . '/../controllers/controllers.php';

$home = new Collection();
$home->setHandler( new HomeController(), true );
$home->get('/', 'index');
$app->mount($home);

/controllers/controllers.php

use Phalcon\Mvc\Controller;

class HomeController extends Controller {
    function index() {
        return 'Hello World!';
    }
}

Expected Behavior

Displaying Hello World! if visiting /public/index.php.

Actual Behavior

Displays Uncaught InvalidArgumentException: Parameter 'definition' must be a string in C:\xampp\htdocs\phalcon\config\routes.php:16 Stack trace: #0 [internal function]: Phalcon\Mvc\Micro\LazyLoader->__construct(Object(HomeController)) #1 C:\xampp\htdocs\phalcon\config\routes.php(16): Phalcon\Mvc\Micro->mount(Object(Phalcon\Mvc\Micro\Collection)) #2 C:\xampp\htdocs\phalcon\bootstrap\bootstrap.php(11): require('C:\\xampp\\htdocs...') #3 C:\xampp\htdocs\phalcon\public\index.php(7): require('C:\\xampp\\htdocs...') #4 {main} thrown in C:\xampp\htdocs\phalcon\config\routes.php on line 16

Workaroud

Removing the parameter true in /config/routes.php file at the line $home->setHandler( new HomeController() ); seems to remove the issue but we loose the lazy loading feature.

Details

Phalcon version

Web framework delivered as a C-extension for PHP
phalcon => enabled
Author => Phalcon Team and contributors
Version => 3.2.0
Build Date => Jun 18 2017 19:06:21
Powered by Zephir => Version 0.9.8-6335775f25

Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.events => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.orm.column_renaming => On => On
phalcon.orm.not_null_validations => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.enable_literals => On => On
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.ignore_unknown_columns => Off => Off
phalcon.orm.update_snapshot_on_save => On => On
phalcon.orm.disable_assign_setters => Off => Off

PHP version

PHP 7.0.13 (cli) (built: Nov 8 2016 13:45:28) ( ZTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

Operating System

Windows 8.1 64 bits

Installation type

Downloaded php_phalcon.dll and placed it in php/ext/ folder in my XAMPP instance + updated php.ini file.

Server

Appache

not a bug

Most helpful comment

All 2 comments

You need to use string, not class instance, use HomeController::class

Was this page helpful?
0 / 5 - 0 ratings