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

Post board existence check. A good way?


class BoardController extends \Phalcon\Mvc\Controller
{

    private function board_id_check($board_id)
    {
        if (false) {
            $this->flash->error("Board does not exist");

            $this->response->redirect('main');
        }
    }

    public function viewAction($board_id)
    {
        $this->board_id_check($board_id);
    }

    public function listAction($board_id)
    {
        $this->board_id_check($board_id);
    }

    public function writeAction($board_id)
    {
        $this->board_id_check($board_id);
    }

    public function modifyAction($board_id)
    {
        $this->board_id_check($board_id);
    }

}

Hello.

I think this way is inefficient. Is there a good way?

I'd like to deal with it at once.

thanks.

There is initialize event. Also im not sure what this code is doing. Is it checking for model if it's exists ? There is already model binding in controllers. Also wait for 3.1.0 where i will add afterBinding event and option to get bound models from dispatcher - so this way you can simplify your code.