How to add prefix to a controller in Phalcon PHP

半腔热情 提交于 2019-12-24 21:48:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!