Esempio n. 1
0
 /**
  * Push the request data into the model state
  *
  * @param	string		The action to execute
  * @return	mixed|false The value returned by the called method, false in error case.
  * @throws 	KControllerException
  */
 public function execute($action, $data = NULL)
 {
     //Create a context object
     if (!$data instanceof KCommandContext) {
         $context = $this->getCommandContext();
         $context->data = $data;
         $context->result = false;
     } else {
         $context = $data;
     }
     $result = parent::execute($action, $context);
     $return_json = array(KRequest::type() == 'AJAX', KRequest::get('get.format', 'cmd') == 'json', !is_string($result), $this->_redirect_message, $this->_auto_json_result);
     if (count($return_json) === count(array_filter($return_json))) {
         $data = is_object($result) && method_exists($result, 'getData') ? $result->getData() : $result;
         //@TODO get rid of msg legacy, use message in the future
         $result = json_encode(array('msg' => $this->_redirect_message, 'message' => $this->_redirect_message, 'result' => $data));
         //@TODO workaround for preventing 404 response headers
         //$context->status = KHttpRequest::OK;
         //Workaround for KDispatcherAbstract::_actionForward
         //@TODO submit patch, or similar for this limitation
         //@see KDispatcheAbstract line 43 - 45 where the forward is made if request isn't POST
         if (KRequest::method() != 'GET') {
             $identifier = clone $this->getIdentifier();
             $identifier->path = array();
             $identifier->name = 'dispatcher';
             $dispatcher = KFactory::get($identifier)->unregisterCallback('after.dispatch', 'forward');
         }
     }
     return $result;
 }