cola
cola

Reputation: 12466

How can i set same title for all actions/views of a controller?

All actions/views will have same title.

Like=>

<?php $this->set('title_for_layout', 'mysite'); ?>

How can I set this title for all actions/views in CakePHP ?

Upvotes: 1

Views: 489

Answers (3)

Nasreddine
Nasreddine

Reputation: 37848

In your app controller set it in the beforeFilter() callback function

class AppController extends Controller
{
    function beforeFilter()
    {
        $this->set('title_for_layout','Your title');
    }
}       

Upvotes: 1

while1
while1

Reputation: 3370

In a controller you can set:

function beforeFilter() {

$this->pageTitle = "my page title";

parent::beforeFilter(); }

Upvotes: 1

Ross
Ross

Reputation: 17987

If you just want your site's name to appear on every page; I would simply set it manually in your layout:

<title><?php echo $title_for_layout; ?> - My Site Name</title>

that way you can have a dynamic title, and have your site's name appear in the <title> of the page.

If you don't want this, you could set the value in a beforeFilter in your app_controller.php:

function beforeFilter() {
    parent::beforeFilter();
    $this->set('title_for_layout', 'My Site');
}

This will give every action/view the title My Site, and you can overwrite this on a per controller/action basis if needed.

Your page title should really be unique for every page however (generally); so unless you have a reason for having the same title I would consider otherwise.

Upvotes: 4

Related Questions