We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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,
    ]);
}


85.5k

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 ?



32.2k
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



12.4k


43.9k

Hi,

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



12.4k

@emiliodeg it works too

return $this->view;



12.4k

thanks to everybody



12.4k

now I can use 3 options

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