Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Zend\View\Renderer\PhpRenderer properties unaccessable #4385

Open
h3lpd3sk opened this Issue · 4 comments

2 participants

@h3lpd3sk

For a recursive render I'd ideally need the current template from the PhpRenderer.
However there's no method for accessing the __template property.
Since it's private even there's no point in extending the PhpRenderer either.

Think this and perhaps other properties should be accessible through methods or overloading.

Not sure what the philosophy behind this is, sure there's one I might be overlooking?

Work around with ReflectionObject isn't really a good solution but possible...

//.phtml
$reflection = new ReflectionObject($this);
$property = $reflection->getProperty('__template');
$property->setAccessible(true);
$template = $property->getValue($this);
@weierophinney

Template name, or template file? The latter can be accessed within the template itself using the __FILE__ magic constant...

@h3lpd3sk

FILE gives full path, $__template holds relative.

So they are not the same.
Would need to parse FILE in order to get same, not sure if there's a real re-usable logic in that?
Would make sense to just be able to get it from Renderer
Not even sure what happens with Map Strategy?

example:

//partial.phtml
$reflection = new ReflectionObject($this);
$property   = $reflection->getProperty('__template');
$property->setAccessible(true);
$template   = $property->getValue($this);

foreach($items as $item){
   if($item->hasChildren()){
     //render recursive
     echo $this->partial($template /* this is what I need*/, array('items' => $item->getChildren()));
   }
}

Is there any reason why this particular variable isn't available?

@weierophinney

Is there any reason why this particular variable isn't available?

Nobody's ever requested it before. :)

Thanks for the use case example -- it makes the request much more clear.

@h3lpd3sk

You're welcome,

Would have made the required code changes and a pull request if I knew howto.
Can't be more then a few lines of code...
Just getting out of svn :-)

So now what?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.