There are two modules - Comments and Pages with their structure, i.e. the implementation is not standard as default in Yii2. Respectively two controllers
class CommentsController extends BaseController { public function actionIndex() { return $this->render('index'); } } Event::on(PagesController::className(), PagesController::EVENT_GET_COMMENTS, function ($event) { echo 'comments'; });
well and similarly for Pages
class PagesController extends BaseController { const EVENT_GET_COMMENTS = ''; public function actionIndex() { $this->trigger(self::EVENT_GET_COMMENTS); return $this->render('index'); } }
In theory, when calling the Pages controller, the index
action should trigger the EVENT_GET_COMMENTS
event and output comments
, but this does not happen :(