PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Setting the Inflector Target

The inflector target is a string with some placeholders for variables. Placeholders take the form of an identifier, a colon (':') by default, followed by a variable name: ':script', ':path', etc. The filter() method looks for the identifier followed by the variable name being replaced.

You can change the identifier using the setTargetReplacementIdentifier() method, or passing it as the third argument to the constructor:

<?php
// Via constructor:
$inflector = new Zend_Filter_Inflector('#foo/#bar.#sfx'null'#');

// Via accessor:
$inflector->setTargetReplacementIdentifier('#');

Typically, you will set the target via the constructor. However, you may want to re-set the target later (for instance, to modify the default inflector in core components, such as the ViewRenderer or Zend_Layout). setTarget() can be used for this purpose:

<?php
$inflector 
$layout->getInflector();
$inflector->setTarget('layouts/:script.phtml');

Additionally, you may wish to have a class member for your class that you can use to keep the inflector target updated -- without needing to directly update the target each time (thus saving on method calls). setTargetReference() allows you to do this:

<?php
class Foo
{
    
/**
     * @var string Inflector target
     */
    
protected $_target 'foo/:bar/:baz.:suffix';

    
/**
     * Constructor
     * @return void
     */
    
public function __construct()
    {
        
$this->_inflector = new Zend_Filter_Inflector();
        
$this->_inflector->setTargetReference($this->_target);
    }

    
/**
     * Set target; updates target in inflector
     *
     * @param  string $target
     * @return Foo
     */
    
public function setTarget($target)
    {
        
$this->_target $target;
        return 
$this;
    }
}

Zend Framework