On Tue, Oct 19, 2010 at 11: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?
You're also asking for more problems by having a slug as the first
part of the URL. To do that, you'd have to create routes for every
single action (including admin_*) and include them before this one.
Either that, or your regexp to match on department would have to
include the literal names of all departments, eg:
array('department' => '[foo|bar|this|that|another|and_another]'
That way, the regexp wouldn't match on your other controllers. But you
can probably see that this would be yet another maintenance nightmare.
Better to do this through a single controller. Create a Booking model
and a Department model. That way, it shouldn't matter how many new
departments are added.
BookingsController:
Router::connect(
'/bookings/:dept',
array('controller' => 'bookings', 'action' => 'view'),
array('dept' => '[a-z]+', 'pass' => array('dept')
);
Router::connect(
'/bookings/:dep/addt',
array('controller' => 'bookings', 'action' => 'add'),
array('dept' => '[a-z]+', 'pass' => array('dept')
);
public function view($dept = null) {
public function add($dept = null) {
Note that you wouldn't strictly need to add Department to
BookingsController's $uses array. As long as you properly associate it
with Booking model, you can do $this->Booking->Department->find(...)
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