本文介绍了如何在Phalcon PHP中为控制器添加前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用具有管理部分mywebsite.com/admin

I'm working on a website using Phalcon PHP that has an admin section mywebsite.com/admin

我创建了两个不同的控制器文件夹(frontend-controllersbackend-controllers) an,具体取决于URL,我正在加载正确的文件夹.

I have created two different controller folders (frontend-controllers & backend-controllers) an depending on the URL, I'm loading the right folder.

我想为所有后端控制器添加一个前缀(admin).

I would like to add a prefix (admin) to the all backend controllers.

mywebsite.com/admin/my-backend-controller-/myaction

代替

mywebsite.com/my-backend-controller-/myaction

我想知道是否有可能,以及如何做到.

I would like to know if it's possible and how to do it.

推荐答案

可以通过使用自定义路由来实现.

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",
    )
);

或者将其概括化:

//Define a route
$router->add(
    "/admin/:controller/:action/:params",
    array(
        "controller" => 1,
        "action"     => 2,
        "params"     => 3,
    )
);

文档中的更多信息

这篇关于如何在Phalcon PHP中为控制器添加前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 10:11