Bear with me if this is a bit confusing at first. There's a bug (/mis-
design, whatever) surrounding routing and using prefixes - this is
Cake v1.2 RC2.

It's come up a few times before in this group, but by developers who
haven't really understood why they've been getting the behavior they
have, so the underlying problem hasn't been identified (that I can
see). Some example problems that arise:
- prefixed routes mangle like so: /controller/prefix_action/ (from
paginator, html etc - they should be /prefix/controller/action/)
- routes (from paginator, html etc) add the prefix when they shouldn't
- routes (from paginator, html etc) don't add the prefix when they
should

It stems from the fact that the Router - specifically in Router::url()
- checks for admin routes through Configure::read('Routing.admin'). As
it should - however, it does NOT check for prefixes (and indeed, there
is no enumeration of prefixes anywhere, so it would be non-trivial for
it to do so).

If the Routing.admin is set to say 'admin', then Router::url() only
checks for routes with '$admin => true'. However, if you have a prefix
that is NOT Routing.admin - say 'members' (when Routing.admin is set
to 'admin'), then Router::url() will not include the check for
'$members => true'.


An example situation in which this causes a problem:

Application has two prefixes:
  /admin
  /members
Routing.admin in core.php can only be set to a string, so it's set to
'admin'
You are in /members/users/index (UsersController->members_index())
You run a Paginator, the Paginator checks to see if you're in the
'admin' prefix (for whether to include the '$admin => true' check on
routes. You're not.
The Paginator will match any routing rule for the Users controller -
regardless of prefix!


How to replicate:

Create a controller with a prefixed and non-prefixed 'index' action.
Eg an ObjectsController with a 'function index()' and a 'function
members_index()'. Note that the prefix MUST NOT EQUAL
Configure::read('Routing.admin') - so it should be a secondary/
tertiary/etc prefix.

Put any link in the views - use a Paginator, use HTML::link(), use a
Form. The output will be wrong most of the time. How it's wrong will
depend on what your routing configuration is, and in which order the
statements appear.


Fix?

This is going to be annoyingly non-trivial to fix. Perhaps
Routing.admin should be an array that enumerates all the prefixes of
an app? But that'd likely change a whole of other stuff?

In my case, I've just hacked a hard-coded bit of gunk into
Router::url() below the $admin checking bit (one for each of my
prefixes). If anyone else has this bug, I'll see if I can paste some
code here as an example (although this is a TEMP fix - it's ugly as
hell).


If that still doesn't make any sense, umm, I'll try and explain
better. Does Google Groups format code nicely? Might be easier to
explain by pointing to the bits of router.php that apply?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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