On Jan 14, 2008 4:30 PM, Chris Hartjes <[EMAIL PROTECTED]> wrote:

>
>
> On Jan 14, 2008 4:22 PM, b logica <[EMAIL PROTECTED]> wrote:
> >
> > Here's one:
> >
> > http://bakery.cakephp.org/articles/view/taking-advantage-of-the-pages-controller
> >
> > -- snip --
> > Route placement
> > Just for reference, you should place the /* route LAST in your routes file
> > or it will override all of the other routes. posted Sun, Oct 22nd 2006,
> > 18:44 by Luke Sheridan
> > -- snip --
>
> Hrm, I hadn't seen that before.  Thanks for pointing it out.  I know
> that some other frameworks do that sort of thing, where  URL's filter
> down through a chain of custom routes.
>
>

I didn't think it was chaining, but that the first route to match
would end "searching" through the rest for a candidate.

>
> > Should I be using a "/*" route? Do I need to specify "/about/*" goes to
> > pages? If so, is there some way that I can keep those views nested like
> > this:
> >
> > views
> >   pages
> >     about
> >       something
> >         something deeper
> >
> > With the structure like this, if I try a route like "/about/*" I run into
> > problems because Cake no longer sees the view inside the about dir. I have a
> > lot of static pages and I'd really like to be able to keep them organised,
> > rather than dumping everything in the  /app/views/pages/ dir.
>
> Hrm...sounds like you will need a lot of custom routes to make it
> happen, but that's because I've never done what you're trying to do
> (with respect to having a huge collection of static pages).
>
>
>
>

Right now, if i put the /* route at the top, I can browse to static
pages with paths like so:

/about/qas/agenda

where the same directory structure exists under the views/pages/ dir.
But if I try to browse to a controller (/newsletter/) I get:

-- snip --
Missing View

 Error: The view for PagesController::display() was not found.
 Error: Confirm you have created the file:
/var/www/vhosts/cake_elan/app/views/pages/newsletter.ctp
 Notice: If you want to customize this error message, create
app/views/errors/missing_view.ctp
-- snip --

If I put the route at the bottom I get the same error, only it's for
an element I have in my newsletter view (get_archive_list.ctp). In
that file, I have the following:

$archive_list = $this->requestAction('Newsletters/get_archive_list');

So I just created a new route:

Router::connect('Newsletters/get_archive_list', array('controller' =>
'newsletters', 'action' => 'get_archive_list'));

And that's working. So, I guess you're right, and I'll need to set a
route for every element, etc. that I use.

...

Ah--I think I have something. For posterity (and, because I may be
shooting myself in the foot):

All of the static pages are under 3 different directories within the
views/pages/ dir. I wanted a way that I can create just 1 route per
directory:

Router::connect('/about/*', array('controller' => 'pages', 'action' =>
'display'));
Router::connect('/archive/*', array('controller' => 'pages', 'action'
=> 'display'));
etc.

If browse to /about/whatever/ the parent "about" directory is ignored
and whatever can't be found. That is, with the "/*" route, the $path
var in pages_controller is:

Array
(
    [0] => about
    [1] => whatever
)

When I change the route to "/about/*" I get:

Array
(
    [0] => whatever
)


So I wanted some way to pass "about" to the pages_controller so that
it tacks that on to the beginning of the path. I knew that I could
pass in params from the route but I didn't realise that whatever I
passed in would be prepended to the list of params (which are the
following path elements).

So o pass in the top-level dir as the 1st param using the  route:

Router::connect('/about/*', array('controller' => 'pages', 'action' =>
'display', 'about'));

Array
(
    [0] => about
    [1] => whatever
)

And this allows me to remove the routes for elements hack (at least,
it seemed like a hack) so that requestAction can do its thing.

Long story short: I think it's OK now.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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