views:

2853

answers:

5

Has anyone run into this problem...

In my layout.phtml I have:

<head>
    <?= $this->headTitle('Control Application - ') ?>
</head>

then in index.phtml I have:

<? $this->headTitle()->append('Client List'); ?>

I expect that, when I go to my index action, the title should be 'Control Application - Client List' but instead I have 'Client ListControl Application - '

What is going on? How can I fix this?

+1  A: 

I don't actually use headTitle, but do use ZF, and I had a quick look on the mailing list, this might solve the problem:

<head>
    <?= $this->headTitle('Control Application') ?>
</head>

Then:

<?php
$this->headTitle()->setSeparator(' - ');
$this->headTitle()->prepend('Client List');
?>
Jack Sleight
this actually results in 'Client List - Control Application' instead of 'Control Application - Client List'.
Andrew
OH, oops. Well that should be fixed by using prepend instead of append (I've updated my answer), but you already have that in another answer, so never mind :-) .
Jack Sleight
+6  A: 

Default behaviour of the headTitle() is to append to the stack. Before calling headTitle() in layout.phtml, your stack is:

Clientlist

Then, you call headTitle with the first argument and no second argument (which makes it default to APPEND), resulting in the following stack:

ClientListControl Application -

The solution, in layout.phtml:

<?php 
    $this->headTitle()->prepend('Control Application -');
    echo $this->headTitle();
?>
Aron Rotteveel
+4  A: 

Additionally, you can use the setPrefix method in your layout as such:

<head>
    <?= $this->headTitle()->setPrefix('Control Application') ?>
</head>

And in your controllers/actions/etc use the standard append/prepend:

<?php
$this->headTitle()->setSeparator(' - ');
$this->headTitle()->append('Client List');
?>
gmcrist
A: 

This happens because the layout is the last script to be executed. So you actually do the append BEFORE the set of the title, so that there's nothing to append to yet. Set the main title (Control Application) in a Controller. For example I always do it in the predispatch action of a initPlugin so that it is execute before any other Controller Action, and I can append or prepend at will.

To use such a plugin just define a new Class extending Zend_Controller_Plugin_Abstract and define a function preDispatch(Zend_Controller_Request_Abstract $request) where you can put all your common-to-the-whole-site code, and to register the plugin just put it into the controllerFront of your bootstrap: $controller->registerPlugin(new InitPlugin());

Emanuele
A: 

Thanks.. It helped a lot.