Search code examples
parameterstypo3defaultextbasetypo3-7.6.x

typo3 controller error when no parameters, how to set defaults


I have a form that is accessed in various ways, sometimes there are 2 variables transported ... with every template I define the variables but with a direct link I get an error, probably because $newTicket is not defined ...

how can I give default values ? does that resolve the error ??

/**
 * action form
 * 
 * @param array $newTicket
 * @return void
 */
public function formAction($newTicket = array('origin' => '', 'destination' => '')) {
    $this->view->assign('ticket', $newTicket);
}

Solution

  • If you dont want to make an param needed you only must set its default value.

    /**
     * action form
     * 
     * @param array $newTicket
     * @return void
     */
    public function formAction($newTicket = array()) {
        $this->view->assign('ticket', $newTicket);
    }
    

    after changing, clear all your typo3 cache in the install tool.