Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

return in view

Hello. I do right, when I want to abort the further execution?

public function indexAction()
{
    //...

    if ($error >= Main::ERROR_LIMIT) {
        $this->view->setVars([
            'hiddenForm' => true,
        ]);

        return;
    }

    //do something ...

    $this->view->setVars([
        'form'        => $form,
    ]);
}


60.8k

return this->view->pick i think this is how i do it

or wrap the whole controller in if else.

return false doesnt work for sure, but u can try with return true ?



4.9k
Accepted
answer

Hi @dan you can return the view or pick another

public function indexAction()
{
    //...

    if ($error >= Main::ERROR_LIMIT) {
        $this->view->setVars([
            'hiddenForm' => true,
        ]);

        return $this->view;  //goes to index.volt or phtml if you dont use volt engine
    }

    //do something ...

    $this->view->setVars([
        'form'        => $form,
    ]);

    $this->view->pick('other-view'); //render other view file
}

picking views docs



6.1k


29.9k

Hi,

you may accept Izo answer so that the thread is marked as solved. It may be helpfull for others



6.1k

@emiliodeg it works too

return $this->view;



6.1k

thanks to everybody



6.1k

now I can use 3 options

return true;
return $this->view;
return $this->view->setVars([
            ...
]);