When I use PHP 5.6.30 + Phalcon 2.0.13 this method works fine everywhere, including my libraries or models classes. But when I started using PHP 7.2.4 + Phalcon 3.0.14 this aproach no longer works. Here is few examples of what I mean.
/project/app/config/bootstrap.php
$di->set('dispatcher', function() {
$dp = new Dispatcher();
$dp->setControllerSuffix('');
$dp->setActionSuffix('');
$dp->setDefaultNamespace('Project\Controllers');
return $dp;
}); #dispatcher
/project/app/controllers/Index.php
namespace Project\Controllers;
class Index extends Base {
function index() {
$test = $this->dispatcher->getParam('test');
echo $test;
} #index
} #class
This above example works with my controller. However when I try using similar in my library or model it doesn't work.
/project/app/libraries/Helper.php
namespace Project\Libraries;
class Helper {
function test() {
$test = $this->dispatcher->getParam('test');
return $test;
} #test
} #class
Then when I try calling it from my Index controller it doesn't work.
/project/app/controllers/Index.php
namespace Project\Controllers;
use Project\Libraries\Helper;
class Index extends Base {
function index() {
echo Helpher::test();
} #index
} #class
All I see is this following error;
Error: Using $this when not in object context
Is there a way to reuse my dispatcher from bootsrap in libraires or models too? Some examples would be apreceated.
What would you recommend? Thank you!