Answer the question
In order to leave comments, you need to log in
How to pass value from plugin to initialize controller?
I'm just learning.
connect the plugin
$di->set('dispatcher',function() {
$eventManager = new EventsManager;
$eventManager->attach("dispatch:beforeException", new ExceptionsPlugin);//404
$eventManager->attach("dispatch:beforeDispatch", new MyPlugin);
$dispatcher = new MvcDispatcher;
$dispatcher->setEventsManager($eventManager);
return $dispatcher;
});
use Phalcon\Events\Event;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\User\Plugin;
class MyPlugin extends Plugin
{
public function beforeDispatch(Event $event, Dispatcher $dispatcher)
{
$MyResult = "тест";
// $this->response->redirect('/errors');
return $MyResult;
}
}
use Phalcon\Mvc\Controller;
use Phalcon\Mvc\View\Engine\Volt;
class IndexController extends Controller
{
public function initialize()
{
// тут я понятия не имею что писать )
$this->view->setVar('MyResult ', $MyResult);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question