/** * Display action * * If the controller was not dispatched manually load the langauges files * * @param KCommandContext A command context object * @return KDatabaseRow(set) A row(set) object containing the data to display */ protected function _actionDisplay(KCommandContext $context) { //Load the language file for HMVC requests who are not routed through the dispatcher if (!$this->isDispatched()) { KFactory::get('lib.joomla.language')->load('com_' . $this->getIdentifier()->package); } return parent::_actionDisplay($context); }
/** * Initializes the default configuration for the object * * Called from {@link __construct()} as a first step of object instantiation. * * @param KObjectConfig $config An optional ObjectConfig object with configuration options. * @return void */ protected function _initialize(KObjectConfig $config) { $toolbars = array(); $toolbars[] = $this->getIdentifier()->name; if ($this->getIdentifier()->domain === 'admin') { $toolbars[] = 'menubar'; } $config->append(array('toolbars' => $toolbars)); parent::_initialize($config); }
protected function _actionRender(KControllerContextInterface $context) { $result = false; if($this->execute('browse', $context) !== false) { //Do not call parent. Parent will re-execute. $result = KControllerView::_actionRender($context); } return $result; }
/** * Supports a simple form Fluent Interfaces. Allows you to set the request properties by using the request property * name as the method name. * * For example : $controller->limit(10)->browse(); * * @param string $method Method name * @param array $args Array containing all the arguments for the original call * @return KControllerModel * * @see http://martinfowler.com/bliki/FluentInterface.html */ public function __call($method, $args) { //Handle action alias method if (in_array($method, $this->getActions())) { //Get the data $data = !empty($args) ? $args[0] : array(); //Set the data in the request if (!$data instanceof KCommandInterface) { //Make sure the data is cleared on HMVC calls $this->getRequest()->getData()->clear(); //Automatic set the data in the request if an associative array is passed if (is_array($data) && !is_numeric(key($data))) { $this->getRequest()->getData()->add($data); } } } //Check first if we are calling a mixed in method to prevent the model being //loaded during object instantiation. if (!isset($this->_mixed_methods[$method])) { //Check for model state properties if (isset($this->getModel()->getState()->{$method})) { $this->getRequest()->getQuery()->set($method, $args[0]); $this->getModel()->getState()->set($method, $args[0]); return $this; } } return parent::__call($method, $args); }
/** * Render an error * * @throws InvalidArgumentException If the action parameter is not an instance of KException * @param KControllerContextInterface $context A controller context object * @return string */ protected function _actionRender(KControllerContextInterface $context) { //Check an exception was passed if (!isset($context->param) && !$context->param instanceof KException) { throw new InvalidArgumentException("Action parameter 'exception' [KException] is required"); } //Set the exception data in the view $exception = $context->param; //If the error code does not correspond to a status message, use 500 $code = $exception->getCode(); if (!isset(KHttpResponse::$status_messages[$code])) { $code = '500'; } $message = KHttpResponse::$status_messages[$code]; //Get the exception back trace $traces = $this->getBackTrace($exception); //Traverse up the trace stack to find the actual function that was not found if (isset($traces[0]['function']) && $traces[0]['function'] == '__call') { foreach ($traces as $trace) { if ($trace['function'] != '__call') { $message = "Call to undefined method : " . $trace['class'] . $trace['type'] . $trace['function']; $file = isset($trace['file']) ? $trace['file'] : ''; $line = isset($trace['line']) ? $trace['line'] : ''; $function = $trace['function']; $class = $trace['class']; $args = isset($trace['args']) ? $trace['args'] : ''; $info = isset($trace['info']) ? $trace['info'] : ''; break; } } } else { $message = $exception->getMessage(); $file = $exception->getFile(); $line = $exception->getLine(); $function = isset($traces[0]['function']) ? $traces[0]['function'] : ''; $class = isset($traces[0]['class']) ? $traces[0]['class'] : ''; $args = isset($traces[0]['args']) ? $traces[0]['args'] : ''; $info = isset($traces[0]['info']) ? $traces[0]['info'] : ''; } //Create the exception message if (!ini_get('display_errors')) { $traces = array(); } $this->getView()->exception = get_class($exception); $this->getView()->code = $code; $this->getView()->message = $message; $this->getView()->file = $file; $this->getView()->line = $line; $this->getView()->function = $function; $this->getView()->class = $class; $this->getView()->args = $args; $this->getView()->info = $info; $this->getView()->trace = $traces; $this->getView()->level = $exception instanceof KExceptionError ? $exception->getSeverityMessage() : false; //Render the exception $result = parent::_actionRender($context); return $result; }
/** * Supports a simple form Fluent Interfaces. Allows you to set the request * properties by using the request property name as the method name. * * For example : $controller->view('name')->limit(10)->browse(); * * @param string Method name * @param array Array containing all the arguments for the original call * @return KControllerBread * * @see http://martinfowler.com/bliki/FluentInterface.html */ public function __call($method, $args) { //Check first if we are calling a mixed in method. This prevents the model being //loaded durig object instantiation. if (!isset($this->_mixed_methods[$method])) { //Check if the method is a state property $state = $this->getModel()->getState(); if (isset($state->{$method})) { $this->{$method} = $args[0]; return $this; } } return parent::__call($method, $args); }
/** * Push the request data into the model state * * @TODO this is because KControllerBread have $data = null, while KControllerAbstract requires it to be KCommandContext */ public function execute($action, $data = null) { if (!is_a($data, 'KCommandContext')) { $data = new KCommandContext(); } return parent::execute($action, $data); }