Hello everyone. There is a basic controller BackendController. Inherited by other controllers. Please help me to organize for their support of the event, ie, to be able to expand with ItemController CategoryController and vice versa, for example.
<?php
//BackendController
namespace Core\Controllers;
class BackendController extends \Phalcon\Mvc\Controller
{}
//ItemController
class ItemController extends \Core\Controllers\BackendController
{
public function indexAction()
{
}
}
//CategoryController
class CategoryController extends \Core\Controllers\BackendController
{
public function indexAction()
{
}
}
//PageController
class PageController extends \Core\Controllers\BackendController
{
public function indexAction()
{
}
}
//etc
Please help me to organize dynamically opportunity to expand one class by another, a rough example:
<?php
//ItemController
class ItemController extends \Core\Controllers\BackendController
{
public function indexAction()
{
echo 'ItemController';
}
}
//CategoryController
class CategoryController extends \Core\Controllers\BackendController
{
public function indexAction()
{
$extraData = 'extends from CategoryController';
$eventsManager->fire("item:beforeIndexAction", $this, $extraData);
}
}
Accordingly, when the method is called in the controller indexAction ItemController, should receive:
<?php
ItemController extends from CategoryController
Ideally, I can extend action of any controller in another controller action of any inherited from BackendController
Life example. When editing the item(ItemController editAction) I want to load a list of categories(CategoryController getCategoriesAction), but ItemController should not depend on CategoryController, so if i delete CategoryController, ItemController should continue to work, but list of categories(CategoryController getCategoriesAction) would no longer be available on it.