I'm working on an overhaul of a CakePHP app I built under CakePHP 1.2. I've upgraded to 1.3 and am considering moving away from the admin routing paradigm for my application. I'm finding that some of my controllers are getting extremely large because of duplicate functions for front end and admin. My intuition is that it is much cleaner to just create a set of admin controllers and drop the admin routing all together, but I wanted to get input on what others are doing and what, if any, functionality I'm going to miss out on dropping the routing.
What are considered best practices for a robust CakePHP app (or other MVC framework) in this regard?
I'd suggest to simply separate front-end application and admin into two separate applications (/app
and /admin
). Just think of admin as a simple front-end application, doing all the "dirty" work with the database.
By doing so, you'll be able to access your admin using /admin prefix in URL or set DocumentRoot to /admin/webroot and access admin using subdomain (i.e. admin.myapp.com).
To avoid model code duplication, you could put your models into some shared folder (i.e. /vendors/core/models
) and add this path to model paths in bootstrap.php
files (App::build('models' => array(VENDORS . 'core/models/'))
for CakePHP 1.3, $modelPaths = array(VENDORS . 'core/models/')
for CakePHP 1.2).
To add more admin or app specific stuff to your models, you could extend your core models in /models, by loading core model and extending it:
App::import('Model', 'CoreModelName');
class CustomCoreModelA extends CoreModelA
{
function specificMethod() {}
}
That could be made for shared components, behaviors, etc.
ive built apps using admin routing and not, and the not version is always a mess. if some of your methods are the same you can do the following.
function add(){
$this->_add();
}
function admin_add(){
$this->_add();
}
function _add(){
... your code ...
}
i would bet its not all your code that is the same, and not using admin routing you will end up with a lot of code doing if(... is admin ...) { echo 'blaa'} else { echo 'foo'; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With