i have created the front of the website by baking the MVC and done the coding also, at that t开发者_运维技巧ime i haven't backed the admin section.
Now i want to add admin section.which is the best method to do it.
I am running thru the same issue as you. I have create several controllers (articles, users, fotos, etc), but now I have the need to create an admin section before moving forward. After asking questions here, reading the cookbook and doing some research online this is what I think is the best approach:
- Create a
control panel controller
or whatever you want to call it, where you can have an action calledadmin_index
oradmin_display
. This action should act like the home.ctp from the pages controller. Just use admin action so all other users should are denied access to this controller. I would have things there like, latest comments, latest users, visits graphs, comments needing approval, etc. This is an example on how to approach this. - Enable
Routing.prefixes
in yourcore.php
file. (You can find instructions about this in the CakePHP cookbook) - Create admin actions in your controllers such as
admin_index, admin_add
- Create code in the app_controller where
admin
is redirected to thecontrol panel controller
on login - At last, make a
admin layout
and make sure thecontrol panel controller
and alladmin actions
use this layout. In this layout you should create a menu that links to alladmin actions
somewhere in the header and underneath you should have a section where all admin action will be displayed. Theme Forest should have some good control panel examples you can use.
I will be working in my admin system sometime this weekend and If I am successful using this approach I will post the code back in here.
To note: I am also learning CakePHP and although I love it, I can still make beginners mistakes. One thing I would suggest you dont do is start using plugins this early in your game. It will discourage you and sink any hope you have in being successful programming in Cake
there is much more simpler way for this approach....We can use current_controller fie and define admin_function_you_want..There is no need for creating a new controller for admin..you can find notes about it in cake php book
The best method would be to create your own admin panel, however it would be time consuming at time you can also try out a cakephp plugin and looking at the inner coding learn how it is done.
You can give a try with https://github.com/Maldicore/Admin
You can write yours by using tutorial or you can use one of the existing. If you write yourself Auth component must be implemented as a minimum requirement.
精彩评论