We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

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.

How to restrict accessing an action of a controller directly

I want to make the accessing to the contoller PostController::showAction, only from this url: http://localhost/blog/post/:id/:title and not from http://localhost/blog/post/show

So I did this to my router:

$di->set("router", function(){
        $router = new \Phalcon\Mvc\Router();

                "controller" => "post",
                "action"     => "show",
                "id"         => 1,
                "title"      => 2
        return $router;

But it still can be accessed from the unwanted url (http://localhost/blog/post/show) I think that the router should do this restriction, how ?


Pass false as first parameter of Phalcon\Mvc\Router constructor to disable the default routes:

$router = new \Phalcon\Mvc\Router(false);