Ok, I think I finally resolved #2 now as well. It looks as if I will
have to convert my entire app to v1.2 of Cake, but in the end the time
spent will be beneficial. 1.2 has more mature routing capabilities
(along with more mature everything else).

Moving on...

In order to keep some of my app's previously defined routes intact, I
simply had to double them up like so (all examples are now in v1.2):

Existing route ("shortcut" to login action of users controller):
Router::connect('/login', array('controller' => 'users', 'action' =>
'login'));

Additional route added for sub-directory support of the login page
(now /sub1/login and /login both work):
Router::connect('/:subdirectory/login', array('controller' => 'users',
'action' => 'login'), array('subdirectory' => '[a-zA-Z0-9\-]+'));

This is from my last post but I wanted to be all-inclusive (basic sub-
directory support):
Router::connect('/:subdirectory/:controller/:action/*', array(), array
('subdirectory' => '[a-zA-Z0-9\-]+'));

The only downside to this entire approach (other than having to port
my app over to 1.2) is that Cake's default routing of /controller/
action/param no longer works and instead I'm forced to have a sub-
directory "prefix" in every URL that doesn't have an explicit route
entry it matches. This is because every controller name I have in my
app matches the regex pattern in my sub-directory custom route. So if
I call /products/view/42 the "products" portion of the URL matches my
regex and Cake assumes that "view" is actually the controller, which
of course it isn't and so I get a missing controller error. If I
manually re-create the Cake default route:

Router::connect('/:controller/:action/*');

...then my sub-directory routing no longer works because Cake assumes
that the "sub1" in /sub1/products/view/42 is a controller and again I
get the missing controller error. Changing the order of the sub-
directory custom route with the Cake default route doesn't help as one
simply overrides the other once a match is found. I think this is
something I'll have to live with but for my particular application
it's actually acceptable for a web visitor to *have* to be inside a
sub-directory (except for a few static pages that will have explicit
routes configured).



On Jan 8, 1:42 pm, etipaced <[email protected]> wrote:
> I seemed to resolve issue #1 in my last post (thanks again to ADmad
> for prompting me to look through the nightly build's test cases for
> this).
>
> v1.2: Router::connect('/:subdirectory/:controller/:action/*', array(),
> array('subdirectory' => '[a-zA-Z0-9\-]+'));
>
> Now my URL's can be prefixed with anything that matches that regex and
> theprefixwill be available in the view as $this->params
> ['subdirectory']. If I form my $html->links as:
>
> $html->link('Link Name', array('controller' => 'locations', 'action'
> => 'view', 'subdirectory' => $this->params['subdirectory']));
>
> ...then Cake will automatically keep theprefixin the generated URL.
>
> Now I just need to figure out how to utilize my other "alias" routes
> to fall inside this dynamicprefixrouting(see my #2 above). I've
> tried moving the "subdirectory" route to the top and bottom of the
> routes list but had the same results with it.
>
> On Jan 7, 2:34 pm, etipaced <[email protected]> wrote:
>
> > Thanks to ADmad from the IRC channel for this solution:
>
> > v1.1: $Route->connect('/sub1/:controller/:action/*', array());
> > v1.2: Router::connect('/sub1/:controller/:action/*', array());
>
> > There are just 2 downsides to this which I am still trying to resolve:
>
> > 1. How can I dynamically add in these routes so an admin can (via the
> > web interface) add a new sub-directory and theroutingwill
> > automatically behave properly? I tried /*/:controller/:action/* but
> > had no luck.
>
> > 2. How can I preserve my existing custom routes without re-creating
> > them for each sub-directory? For instance, I have $Route->connect('/
> > news', array('controller' => 'articles', 'action' => 'index')). But as
> > I (dynamically) add new sub-directories, I want each sub-directory to
> > utilize this route, too. In other words, adding a new sub-dir should
> > allow for /sub3/news without having to manually add it.
>
> > On Jan 7, 12:17 pm, etipaced <[email protected]> wrote:
>
> > > I have an application (built in 1.1, though may get upgraded to 1.2 if
> > > it helps my situation) that needs an additionalprefixroute added to
> > > it. For example, see the 1.2 manual entry 
> > > here:http://book.cakephp.org/view/544/Prefix-Routing
>
> > > My application already has adminrouting, but I now need to move all
> > > the public (or non-admin routed) pages to a sub-directory (call it
> > > "sub1"), and add an additional sub-directory as well (call it "sub2").
>
> > > My dilemma is that I need sub1 and sub2 to use the exact same
> > > controller functions instead of having their own. Normally when using
> > > prefixing, you write a function to correspond with the specificprefix
> > > in use. For example,www.website.com/admin/users/edit/3wouldactually
> > > call UsersController::admin_edit(). Likewise in the manual entry I
> > > linked to above and for my hypothetical example the 
> > > URLwww.website.com/sub1/locations/view/3wouldcall
> > > LocationsController::sub1_view(). This is a problem for me because I
> > > really want that URL to call LocationsController::view() instead. I
> > > also needwww.website.com/sub2/locations/view/3tocall
> > > LocationsController::view() as well.
>
> > > I plan to set session data in AppController to distinguish which sub-
> > > directory (sub1 or sub2) the current user is in. That value will then
> > > affect my model queries.
>
> > > The further issue is that additional sub-directories (which are
> > > essentially instance copies of the application) will need to be
> > > dynamically added via the admin interface as well. This is why I want
> > > to handle the situation with a mod_rewrite customization or with
> > > Cake'srouting.
>
> > > Any help or assistance is greatly appreciated! I'm also on IRC as
> > > etipaced. Thank you for reading :)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to