问题
I'm working on a website using Phalcon PHP that has an admin section mywebsite.com/admin
I have created two different controller folders (frontend-controllers
& backend-controllers)
an depending on the URL, I'm loading the right folder.
I would like to add a prefix (admin
) to the all backend controllers.
mywebsite.com/admin/my-backend-controller-/myaction
instead of
mywebsite.com/my-backend-controller-/myaction
I would like to know if it's possible and how to do it.
回答1:
It is possible by using custom routes.
$router = new \Phalcon\Mvc\Router();
//Define a route
$router->add(
"/admin/my-backend-controller-/myaction",
array(
"controller" => "my-backend-controller",
"action" => "myaction",
)
);
Or make it general:
//Define a route
$router->add(
"/admin/:controller/:action/:params",
array(
"controller" => 1,
"action" => 2,
"params" => 3,
)
);
More info in docs
来源:https://stackoverflow.com/questions/24893625/how-to-add-prefix-to-a-controller-in-phalcon-php