/** * Load the language if the controller has not been dispatched * * @param ControllerContext $context A controller context object * @return void */ protected function _beforeRender(ControllerContext $context) { $controller = $context->getSubject(); if (!$controller->isDispatched()) { $controller->loadLanguage(); } }
/** * Add the toolbars to the controller * * @param ControllerContext $context * @return void */ protected function _beforeRender(ControllerContext $context) { $controller = $context->getSubject(); // Add toolbars on authenticated requests only. if ($controller->getUser()->isAuthentic()) { //Add the toolbars $toolbars = (array) ObjectConfig::unbox($this->getConfig()->toolbars); foreach ($toolbars as $key => $value) { if (is_numeric($key)) { $this->addToolbar($value); } else { $this->addToolbar($key, $value); } } } //Add the template filter and inject the toolbars if ($controller->getView() instanceof ViewTemplatable) { $controller->getView()->getTemplate()->addFilter('toolbar', array('toolbars' => $this->getToolbars())); } }
/** * Execute an action by triggering a method in the derived class. * * @param string $action The action to execute * @param ControllerContext $context A command context object * @throws Exception * @throws \BadMethodCallException * @return mixed|bool The value returned by the called method, false in error case. */ public function execute($action, ControllerContext $context) { $action = strtolower($action); //Retrieve the context name and subject $subject = $context->getSubject(); $name = $context->getName(); //Execute the action if ($this->invokeCommand('before.' . $action, $context) !== false) { $method = '_action' . ucfirst($action); if (!method_exists($this, $method)) { if (!$this->isMixedMethod($action)) { throw new ControllerExceptionActionNotImplemented("Can't execute '{$action}', method: '{$method}' does not exist"); } else { $context->result = parent::__call($action, array($context)); } } else { $context->result = $this->{$method}($context); } $this->invokeCommand('after.' . $action, $context); } //Reset the context $context->setSubject($subject); $context->setName($name); return $context->result; }