On Fri, Sep 24, 2010 at 4:51 PM, lado77 <[email protected]> wrote:
> Dear Cake Bakers,
>
> In my app (currently being designed) I want to have "pages" database
> table, simply because it is the most suitable name for it (Page
> belongsTo Book, Book hasMany Pages). But this is of course in conflict
> with Cake's default static content serving with its PagesController. I
> really don't want to mix database entity "Page" with static content
> "Page" into the common "PageController" as these 2 are totally
> different things. So I see 2 possible solutions here. One would be to
> rename(refactor) cake's PagesControler to something like
> StaticController and all occurrences in URL from /pages/ to /static/.
> But this seems to me quite stupid e.g. regarding future Cake's release
> updates. Another solution would be to rename "Pages" table to
> something different. But I don't like to complicate obvious and easy
> things such as clear naming conventions. My question is: Have anybody
> had experiences with such situation and what was your solution?

You could always name your model Content instead.

However, what I've done is create my own PagesController and use
display() for DB content. For static pages, I use displayStatic(),
which is identical to the default display() except that I add
$this->viewPath = 'pages/static'; before the call to render(). All
static pages have a route. I figure that, if I've got static pages I'm
unlikely to be changing them often, so creating a route for each isn't
a big deal.

For the DB content, I put the following in bootstrap.php:

$slugs = Cache::read('Pages_slugs');

if (empty($slugs))
{
        App::import('Model', 'Page');
        $page = new Page();
        $slugs = $page->find(
                'list',
                array(
                  'fields' => array('Page.slug'),
                  'order' => 'Page.slug DESC'
                 )
        );
        Cache::write('Pages_slugs', $slugs);
}
Configure::write('Pages_slugs', $slugs);

Then, at the end of routes.php:

Router::connect(
        '/:slug',
        array(
                'controller' => 'pages',
                'action' => 'display'
        ),
        array(
                'slug' => implode(Configure::read('Pages_slugs'), '|'),
                'pass' => array('slug')
        )
);

Just remember to delete the cached list of slugs if a page is added or removed.

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

Reply via email to