Developments of Phalcon
-
For example, there are two controllers--
UserController
andCommentsController
Pseudocod
class UserController { public function indexAction() { var_dump($comments); //если модуль комментариев активен, отдаем комметарии, иначе ничего не отдаем } }
class CommentsController
{
$comments = [];public function afterUserIndexAction()
{
return $comments
}
}
It's tight.
$comments
when summoning methodindexAction
ControllerUserController
? I understand that we need to dig up the side of things, but we need to move on.Phalcon
I don't know how I didn't try it. I mean, I finally want to get some kind of plastic system so that one module can be expanded with another, like that.The event paper rereaded once 10:
-
It's not true. You don't understand the very essence of the flames and controllers. Controller's responding to user action, and you're trying to tell me that the controller is a flame.
What's wrong? ?
- First, all the controllers must be inherited from the base controller Phalcon, they will be accessible to DI and EventManager.
- Second, you're trying to get comments in indexAction, but you've got an event calledafterUserIndexAction."
- Where's the event? Who threw the event, who processed it? I don't understand.
How do you do:
use Phalcon\Mvc\Controller as PhController;
class UserController extends PhController { public function indexAction() { $this->getEventsManager()->fire('user:comments'); $comments = $this->dispatcher->getParam('comments'); if ($comments) { var_dump($comments); //если модуль комментариев активен, отдаем комметарии, иначе ничего не отдаем } } } use Phalcon\Mvc\User\Plugin; use Phalcon\Events\Event; class CommentsPlugin extends Plugin { protected $comments = []; public function comments(Event $event) { $this->dispatcher->setParam('comments', $this->comments); return true; } }
And then in the initialization of DI:
$di['eventsManager'] = function () {
$manager = new \Phalcon\Events\Manager();
$manager->attach('user', new CommentsPlugin);
return $manager;
};