user3636815
user3636815

Reputation: 11

Set title Cakephp 2.x

I am trying to change the title of a page. The default.ctp view has the following code:

<title>
    <?php echo $this->fetch('title'); ?>
     - Welcome
</title>

I'm trying to use the following code in the controller of the page:

$title = 'Overview';
$this->set('title');

But unfortunately I do not see see 'Overview - Welcome', but only the name of the function of the controller followed by ' - Welcome'. Can anyone help me to find the problem why it is not working?

Upvotes: 1

Views: 572

Answers (3)

RANDY
RANDY

Reputation: 1

I think instead of:

$this->set('title');

you must use:

$this->set('title', $title);

Upvotes: 0

Serge S.
Serge S.

Reputation: 4915

You can define what $this->fetch('title') returns using View::assign() function that sets block's value this way:

$this->assign('title', $title);

See more in the documentation about view blocks.

Upvotes: 0

JazzCat
JazzCat

Reputation: 4583

Don't know if $this->set('title') will work

I usually use the 'compact' function to set the variables as they're named.

Like this: $this->set(compact('title')); or just simply this $this->set('title', $title);

Upvotes: 1

Related Questions