Kohana project structure
I am looking into using Kohana for my next project. The site will consist of user registrations (and therefore user profiles) where users will have certain privileges. The site will also have an admin section where admins can go to say whether to block a user or delete a post or view usage statistics, for example. A good comparison site would be a multi-user blog, where every blogger, depending on their rights, can publish / edit / delete blogs ... as an example.
First, I am not sure how to set up the controller / view structure to separate the admin section from the front site. I am using Kohana 3, so I was thinking about the controller structure like: application / classes / controller / front (front-up) ... and application / classes / controller / admin (for the admin section).
Or I notice that you can use the Route class to set up routes so that I can set up the "admin" route. for example: www.example.com/admin will lead to an admin login screen. www.example.com ---> front panel controller.
Also, is there any way to separate the "Admin" views and controllers from the "top" views and the controllers, how to separate them based on the folder structure? Any help is greatly appreciated.
Thanks.
a source to share
You can have a separate application folder for admin and front-end:
- applications
- Classes
- controller
- model
- views
- Classes
- admin_application
- Classes
- controller
- model
- view
- Classes
This approach will allow you to customize each bootstrap environment and separate different files nicely. However, due to this separation, you will need to structure the common code as modules to ensure that functionality is shared across two applications. You could have just duplicated the code, of course, but that would be wrong now, wouldn't it!;)
Another approach would be to have admin subfolders in every folder of one application:
- applications
- Classes
- controller
- admin
- model
- admin
- controller
- Views
- admin
- Classes
This approach leaves the files a little more confusing and can be difficult to work with (depending on your perspective), but it is certainly easier to implement. One of the advantages of this approach is that you can create a / public_html / admin folder and secure it with .htaccess (you will also need to add a copy of the regular index.php file). Then, whenever a request is made to http://yourdomain.com/admin , the .htaccess file will launch and secure your admin application at the web server level. Also, the request will automatically move to the / admin subfolders in different folders, so you also have less work to do when it comes to routing.
In both situations, Kohana's (awesome) routing mechanisms will be used to handle requests that have been sent there, and each one is safe, while the other is from the application access point. I assumed you are using KO3 by the way ...
EDIT
Actually, you can .htaccess secure the admin app if you use the first method as well. You just need to configure the /admin/index.php file to point to the admin app.
a source to share