What you could do is have your router dynamically get the names of all
controllers and cache them for a certain period of time- then use that
cached lists in your routes... anything that wasn't a controller you
would route as a department. Something like this(not tested...
slightly modified from an implementation I used):
$controllerList = Cache::read('controllers_flatlist', 'default');
if ($controllerList === false) {
$controllers = Configure::listObjects('controller');
foreach($controllers as &$value) {
$value = Inflector::underscore($value);
}
$controlerList = $controllers;
array_push($controlerList, 'sitemap', 'robots', 'sitemap.xml',
'robots.txt');
$controllerList = implode('|', $controlerList);
Cache::write('controllers_flatlist', $controllerList);
Cache::write('controllers_list', $controllers);
}
if(empty($controllers)){
$controllers = Cache::read('controllers_list', 'default');
}
if (empty($controllers)) {
$controllers = Configure::listObjects('controller');
Cache::write('controllers_list', $controllers);
}
foreach($controllers as &$value) {
Router::connect('/:department/'. $value . '/*', array(
'controller' => $value
) , array(
'department' => '(?!' . $controllerList . ')[a-zA-Z0-9\-]+'
));
}
On Oct 19, 10:55 am, ianmcn <[email protected]> wrote:
> I develop an internal booking/asset management system for my work, it
> has data separated by department, but I need a way to have the
> department specified in the URL as the first segment. For example:
>
> /:departmentname/bookings/add
>
> After that, the default cakephp conventions would work fine. At the
> moment I achieve this by having the application in many different
> folders, one for each department - but I know that is a seriously bad
> way to do it - it was just a quick way to achieve something to a
> deadline, but the number of departments is getting out of hand, so I
> want to put this right. Can anyone give me some hints as to what
> routing rules I'd need to do this?
>
> Thanks
>
> Ian McNaught
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en