开发者

CakePHP - What is the best approach to create an Admin Section

I am looking for an insight into the best approach to create an administrator section in CakePHP. I've looked at plugins like BrowniePHP as well as others, but I am not entirely satisfied with using plugins. So I am trying to create my own which will encompass the things I need. I;ve looked at some tutorials, but cant find the right answer.

I am currently creating a vast application, which is about 10% done, but I now feel the need to have an admin section before moving on.

Basically I would like a section where I can add new articles, approve comment开发者_JAVA技巧s, deny user access, etc. This section should only be accessible by an administrator.

Also, this administrator section must be able to save to any other model.

I am still learning CakePHP and any detailed instruction would be appreciated.


to create an admin-section the first thing you have to do is to manually edit the core.php within /app/config and write the setting Routing.prefixes. This line should be around line 88 somewhere and you just have to uncomment it.
In case you can't find it, it should look like this:

Configure::write('Routing.prefixes', array('admin'));

So now you can write your admin-functions within your controllers like this:

function admin_edit($id = null) {
    //your admin function
}

You don't need access to every model since your writing these function within your controllers like every other "normal" action.

You just have to connect a route to handle the admin-actions:

Router::connect('/admin/:controller/:action/*', array('admin' => true, 'prefix' => 'admin', 'controller' => 'pages'));
// 'admin' => true is a variable for you so you can check if it's an admin-action which is requested
// 'prefix' => 'admin' means that you can write function with this prefix like above

You can then access these actions via the url http://yourapp.com/admin/controller/action

If you now use the Auth-Component you can write methods for checking if a user is allowed to access these methods.

For further information please read these manual-entrys:

Prefix-Routing
Authentication (Auth-Component)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜