A
A
Alexander Ivanov2017-03-04 00:36:05
Phalcon
Alexander Ivanov, 2017-03-04 00:36:05

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;

  });

plugin code
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;

  }
}

I output to the controller:
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 question

Ask a Question

731 491 924 answers to any question