+ Reply to Thread
Results 1 to 5 of 5

Thread: Little help with headTitle()

  1. #1
    risoknop is offline 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 06:53 PM.

  2. #2
    Tekerson is offline 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

  3. #3
    Eugen is offline Senior Member
    Join Date
    Sep 2008
    Location
    Croatia
    Posts
    400

    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 07:36 AM.

  4. #4
    risoknop is offline 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?

  5. #5
    Tekerson is offline 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

+ Reply to Thread

Similar Threads

  1. headTitle helper help please
    By AuL in forum Model-View-Controller (MVC)
    Replies: 2
    Last Post: 03-04-2010, 09:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts