FOF30\Controller\Controller::execute PHP Method

execute() public method

Executes a given controller task. The onBefore and onAfter methods are called automatically if they exist.
public execute ( string $task ) : null | boolean
$task string The task to execute, e.g. "browse"
return null | boolean False on execution failure
    public function execute($task)
    {
        $this->task = $task;
        if (!isset($this->taskMap[$task]) && !isset($this->taskMap['__default'])) {
            throw new TaskNotFound(\JText::sprintf('JLIB_APPLICATION_ERROR_TASK_NOT_FOUND', $task), 404);
        }
        $result = $this->triggerEvent('onBeforeExecute', array(&$task));
        if ($result === false) {
            return false;
        }
        $eventName = 'onBefore' . ucfirst($task);
        $result = $this->triggerEvent($eventName);
        if ($result === false) {
            return false;
        }
        // Do not allow the display task to be directly called
        if (isset($this->taskMap[$task])) {
            $doTask = $this->taskMap[$task];
        } elseif (isset($this->taskMap['__default'])) {
            $doTask = $this->taskMap['__default'];
        } else {
            $doTask = null;
        }
        // Record the actual task being fired
        $this->doTask = $doTask;
        $ret = $this->{$doTask}();
        $eventName = 'onAfter' . ucfirst($task);
        $result = $this->triggerEvent($eventName);
        if ($result === false) {
            return false;
        }
        $result = $this->triggerEvent('onAfterExecute', array($task));
        if ($result === false) {
            return false;
        }
        return $ret;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Executes a given controller task. The onBefore<task> and onAfter<task> methods are called automatically if they
  * exist.
  *
  * If $task == 'default' we will determine the CRUD task to use based on the view name and HTTP verb in the request,
  * overriding the routing.
  *
  * @param   string $task The task to execute, e.g. "browse"
  *
  * @return  null|bool  False on execution failure
  *
  * @throws  TaskNotFound  When the task is not found
  */
 public function execute($task)
 {
     if ($task == 'default') {
         $task = $this->getCrudTask();
     }
     return parent::execute($task);
 }
All Usage Examples Of FOF30\Controller\Controller::execute