Using lazy loading with Micro, Collection and Controller fails when bootstraping Phalcon with Micro.
require __DIR__ . '/../bootstrap/bootstrap.php';
use Phalcon\Mvc\Micro;
$app = new Micro();
require __DIR__ . '/../config/routes.php';
$app->handle();
use Phalcon\Mvc\Micro\Collection;
require __DIR__ . '/../controllers/controllers.php';
$home = new Collection();
$home->setHandler( new HomeController(), true );
$home->get('/', 'index');
$app->mount($home);
use Phalcon\Mvc\Controller;
class HomeController extends Controller {
function index() {
return 'Hello World!';
}
}
Displaying Hello World! if visiting /public/index.php.
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
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.
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 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
Windows 8.1 64 bits
Downloaded php_phalcon.dll and placed it in php/ext/ folder in my XAMPP instance + updated php.ini file.
Appache
You need to use string, not class instance, use HomeController::class
The documentation for lazy loading in a Micro project is missing this detail.
Most helpful comment
The documentation for lazy loading in a Micro project is missing this detail.