Saturday, October 30, 2010

Re: current page info

On Sat, Oct 30, 2010 at 8:16 PM, cricket <zijn.digital@gmail.com> wrote:
> On Sat, Oct 30, 2010 at 6:49 PM, grandioso
> <something.like.a.phenomenon@gmail.com> wrote:
>> I feel really stupid for asking this, but I'm just noob baker, so...
>> How do I add a "selected" class to a menu item that points to the
>> current page and how do I create a title for the current page ?
>>
>> I created a default layout, and all the pages. Then I created the
>> routes in 'app/config/routes.php' like "Router::connect('/contact',
>> array('controller' => 'pages', 'action' => 'display', 'contact'));".
>> It works just fine, but I have no idea how to add "selected" to the
>> currently selected menu item and how to create a custom title for the
>> page.
>>
>> It would be great if I could just pass the "title" and "selected"
>> string in this array.
>> Is it possible ?
>
> $this->set('title_for_layout', 'some title');
>
> I have this in AppController:
>
> protected function _setPageTitle($title)
> {
>        $title = 'some default text' . (!empty($title) ? " &bull; ${title}" : null);
>        $this->set('title_for_layout', $title);
> }

I forgot to add that this is also in AppController:

function beforeRender()
{
parent::beforeRender();

if (!isset($this->viewVars['title_for_layout']))
{
/* set default title
*/
$this->_setPageTitle();
}
}

and it's:

protected function _setPageTitle($title = null) { ... }

That way, I get the default if I forget to call the method inside some
action. Cake will set the var if you don't, based on the model name,
but that's not always what you might want.

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: