Answer the question
In order to leave comments, you need to log in
Phalcon beforeexecute?
Hello.
I have a question about Phalcon, to be more precise - methods that should work before and after the action is launched.
There is the following:
class ControllerBase extends \Phalcon\Mvc\Controller
{
public function beforeExecuteRoute($dispatcher)
{
echo 'beforeExecute';
}
}
class SomeController extends ControllerBase { public function index(){ echo 'Test'; } }
Answer the question
In order to leave comments, you need to log in
There will be no output in this function (event) - this is a feature.
You can check whether an event occurs or not, like this:
class ControllerBase extends \Phalcon\Mvc\Controller
{
public $p='N';
public function beforeExecuteRoute($dispatcher)
{
$this->p='Y';
}
}
class SomeController extends ControllerBase { public function index(){ echo 'Test '.$this->p; } }
beforeExecuteRoute always outputs data for the default view controller. Any other controllers have their own context, which overrides the default context.
For output in any view:
public function beforeExecuteRoute()
{
$this->view->setVar('param', 'ExecuteRoute');
}
You can try an alternative:
$app = new \Phalcon\Mvc\Micro();
$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach('dispatch:beforeExecuteRoute',
function($event, $dispatcher, $exception) {
throw new \Phalcon\Exception('Fired up!');
});
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$dispatcher->setEventsManager($eventsManager);
$app->setService('dispatch', $dispatcher);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question