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();

        $router->add(
            "/post/([0-9]+)/([a-zA-Z0-9\+\_\-]+)",
            array(
                "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 ?



81.8k
Accepted
answer

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

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