Zend Framework Forum

Go Back   Zend Framework Forum > Zend Framework Forum > General Talks

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-29-2009, 07:50 PM
Junior Member
 
Join Date: Jan 2009
Posts: 26
Default Little help with headTitle()

Hi, I'm new to this forum and also to Zend Framework. I've been writing PHP code for more than 2 years already so I'm not a complete newbie.

I'm stll just trying to get used to ZF (have been playing with it just for a couple of weeks).

What I want to achieve is, in the bootstrap file, to set the title of the pages to be like this:

Code:
Some title - controller - action
Where "controller" should be name of current controller and "action" name of current action. I don't know how to get current controller and action names though.

Thank you for your help

This is how my bootstrap file looks like:

[php]
<?php
error_reporting(E_ALL); // crucial for development environment, goes away in production

defined('APPLICATION_PATH')
or define('APPLICATION_PATH', dirname(__FILE__));
defined('APPLICATION_ENVIRONMENT')
or define('APPLICATION_ENVIRONMENT', 'development');

Zend_Session::start();

$frontController = Zend_Controller_Front::getInstance();
$frontController->setControllerDirectory(APPLICATION_PATH . '/controllers');
$frontController->setParam('env', APPLICATION_ENVIRONMENT);

Zend_Layout::startMvc(APPLICATION_PATH . '/layouts/scripts');
$view = Zend_Layout::getMvcInstance()->getView();
$view->doctype('XHTML1_STRICT');
$view->headTitle('Zend'); // HERE I NEED YOUR HELP

$configuration = new Zend_Config_Ini(
APPLICATION_PATH . '/config/app.ini',
APPLICATION_ENVIRONMENT
);

$dbAdapter = Zend_Db::factory($configuration->database);
Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapt er);

$registry = Zend_Registry::getInstance();
$registry->configuration = $configuration;
$registry->dbAdapter = $dbAdapter;

unset($frontController, $view, $configuration, $registry, $dbAdapter);
[/php]

Last edited by risoknop; 01-29-2009 at 07:53 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-29-2009, 08:44 PM
Senior Member
 
Join Date: Jul 2008
Posts: 288
Default

I don't think you will be able to achieve this in the bootstrap as the routing hasn't been done at this point so the controller and action aren't decided on.
I think the cleanest way to achieve this would be with a controller plugin. So you can retrieve the controller and action names from the request object.
__________________
Brenton Alker
PHP Developer - Brisbane, Australia

blog.tekerson.com | twitter.com/tekerson | brenton.mp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-30-2009, 08:12 AM
Senior Member
 
Join Date: Sep 2008
Location: Croatia
Posts: 356
Send a message via MSN to Eugen
Default

ye, you cant do that in bootstrap..
you can
a) make controller plugin my_controller_plugin extends zend_controller_plugin_abstract
b) make base class my_controller action extends zend_controller_action
c) make a view helper
d) you can copy/paste code in every controller but u can see whats wrong with that approach
e) im sure there are at least 2-3 more thing you can try

but they all come to same idea: you need to access zend_controller_request object and then you can use its getModuleName(), getControllerName() and getActionName() methods witch will return requested names..

Zend Framework: Documentation

Last edited by Eugen; 01-30-2009 at 08:36 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-30-2009, 09:59 PM
Junior Member
 
Join Date: Jan 2009
Posts: 26
Default

Thank you for help

I will probably create a view helper.

Btw, is there any good tutorial on how to create a controller plugin?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-01-2009, 12:33 AM
Senior Member
 
Join Date: Jul 2008
Posts: 288
Default

They are pretty straightforward, and the docs (Zend Framework: Documentation) are pretty good.


Front Controller Plugins in Zend Framework is also quite a good introduction (Google is your friend)
__________________
Brenton Alker
PHP Developer - Brisbane, Australia

blog.tekerson.com | twitter.com/tekerson | brenton.mp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT. The time now is 12:06 AM.


Designed by: Miner Skinz Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0