0

I'm trying to find where Zend implemented the partial() method so that I can add some ACL code into it for permission control. I know that the calling object of the method is always a Zend_View object, and I looked, but the partial method seems to be missing in it (and all the classes/interfaces that it inherits/implements).

Does anybody know how Zend_View acquires that method?

For those of you who are optimization minded and are itching to tell me that I should use render() instead, the partials in question require variable inputs as they play the same kind of roles as a table row partial does. Unless you can show me how to do that with a render() method, please stay on topic.

Also, I'm not intending to modify the Zend Framework code directly, I simply want to override the implementation, but I also want to see the method I'm overriding so that I can see what I'm working with.

NightRaven
  • 401
  • 3
  • 17
  • http://framework.zend.com/manual/1.12/en/zend.view.helpers.html#zend.view.helpers.initial.partial – markus Jan 08 '13 at 20:42
  • That just gives me the information on how to use it (I'm already using it). what I'm asking is, where is ->partial defined so that I can change it does ? Thanks for the quick replies btw – NightRaven Jan 08 '13 at 20:48
  • 1
    If you know it's a view helper, it's easy to find: library\Zend\View\Helper\Partial.php. – markus Jan 08 '13 at 20:49
  • 1
    If you want to implement your own, write your own and add it to the view helper path. If you want to completely replace it, add it to the helper stack with the same name to override the native helper. – markus Jan 08 '13 at 20:54

1 Answers1

1

How to write your own helpers and override default helpers

Since we're talking about a view helper, the code for it can be found in library\Zend\View\Helper\Partial.php. If you want to change what the partial view helper does, write your own helper:

class MyProject_View_Helper_MyHelper extends Zend_View_Helper_Abstract {}

or

class MyProject_View_Helper_MyHelper implements Zend_View_Helper_Interface {}

and then add this helper to the helper stack by adding the path to it to your configuration.

resources.view.helperPath.MyProject_View_Helper_ = "MyProject/View/Helper/"

If you call your helper Partial, you can completely override the default partial helper.

See also this blog about view helpers by Akrabat.

And, to put it in your words...

...how Zend_View aquires the partial method

If a helper is registered, it can be called from the view because of the following code in Zend_View_Abstract

/**
 * Accesses a helper object from within a script.
 *
 * If the helper class has a 'view' property, sets it with the current view
 * object.
 *
 * @param string $name The helper name.
 * @param array $args The parameters for the helper.
 * @return string The result of the helper output.
 */
public function __call($name, $args)
{
    // is the helper already loaded?
    $helper = $this->getHelper($name);

    // call the helper method
    return call_user_func_array(
        array($helper, $name),
        $args
    );
}
Community
  • 1
  • 1
markus
  • 40,136
  • 23
  • 97
  • 142
  • I'll take a look in a moment, can you also explain to me how the Zend_View acquires the partial method?. by that I meant the actual Zend_View object that the controllers have instantiated as $this->view – NightRaven Jan 08 '13 at 21:10
  • Thanks alot, this definitely got me started – NightRaven Jan 08 '13 at 21:23