在Kohana 3.2中为单独管理创建路由和控制器定义

时间:2022-10-13 13:09:35

I am trying to build an administration section in a Kohana 3.2 environment where the goal is to target the following URL:

我正在尝试在Kohana 3.2环境中构建管理部分,其目标是定位以下URL:

domain/admin/controller/action/id

域/管理/控制/操作/ ID

Currently I have a route that is defined and works fine as:

目前我有一个定义的路线,工作正常:

domain/controller/action/id

域/控制器/动作/ ID

My first approach to creating the admin version was this:

我创建管理版的第一种方法是这样的:

Route::set('admin', 'admin/(<controller>(/<action>(/<id>)))');

This will work, but my controllers inside the admin folder have to be another class name as the controllers outside of this folder. I thought if I would like to target admin/user/index I need a Controller_User in the admin folder. This only works if I type admin_user/index, because this uses the default route.

这将有效,但我在admin文件夹中的控制器必须是另一个类名作为此文件夹之外的控制器。我想如果我想定位admin / user / index我需要在admin文件夹中有一个Controller_User。这仅在我输入admin_user / index时有效,因为它使用默认路由。

How do I set up admin folders with routing in Kohana?

如何在Kohana中设置带路由的管理文件夹?

2 个解决方案

#1


3  

I'm not sure if you want it to be in the admin directory or not, but I assume you want to.

我不确定你是否希望它在管理员目录中,但我认为你想要。

First, you have to specify the directory Kohana is going to look in for the route:

首先,您必须指定Kohana将查找路径的目录:

Route::set('admin', 'admin/(<controller>(/<action>(/<id>)))')
    ->defaults(
        'directory' => 'admin'
    );

The you create a file called user.php in application/classes/controller/admin/

你在application / classes / controller / admin /中创建一个名为user.php的文件

And the name of the controller is then Controller_Admin_User

然后控制器的名称是Controller_Admin_User

I hope this helps.

我希望这有帮助。

#2


0  

If I understand correctly - you want to have admin controllers inside admin folder but you want the controller name without admin part - this is not possible, as class name must reflect the folder structure.

如果我理解正确 - 你想在admin文件夹中有管理员控制器,但你想要没有管理员部分的控制器名称 - 这是不可能的,因为类名必须反映文件夹结构。

#1


3  

I'm not sure if you want it to be in the admin directory or not, but I assume you want to.

我不确定你是否希望它在管理员目录中,但我认为你想要。

First, you have to specify the directory Kohana is going to look in for the route:

首先,您必须指定Kohana将查找路径的目录:

Route::set('admin', 'admin/(<controller>(/<action>(/<id>)))')
    ->defaults(
        'directory' => 'admin'
    );

The you create a file called user.php in application/classes/controller/admin/

你在application / classes / controller / admin /中创建一个名为user.php的文件

And the name of the controller is then Controller_Admin_User

然后控制器的名称是Controller_Admin_User

I hope this helps.

我希望这有帮助。

#2


0  

If I understand correctly - you want to have admin controllers inside admin folder but you want the controller name without admin part - this is not possible, as class name must reflect the folder structure.

如果我理解正确 - 你想在admin文件夹中有管理员控制器,但你想要没有管理员部分的控制器名称 - 这是不可能的,因为类名必须反映文件夹结构。