(on Thursday, 10 February 2011, 06:14 AM -0800):
>
> I am currently forced to use zend framework 1.7.2
>
> I have a problem with the partial function
>
> $this->partial('template.html', array('arg1' => 'value1'));
>
> This kind of does what i want as the variables that are available to the
> parent template are not in the partial template
>
> I know that $this->render('template.html'); allows the variables to be
> exposed to the template
>
> but what about if i want the variables to be exposed to my partial template
> AND need parameters to be passed in? Did they actually not put something
> like this in?
>
> yeap i know the partial() method is meant to give a clean variable scope and
> blah blah blah, so if thats the case, how do I do what im asking?
Two ways:
* Use render(), and make sure the variables are already in the view
script scope, or assigned to the view. In terms of having them in the
view script scope:
<?php
$arg1 = 'value1';
echo $this->render('template1.phtml'); // template can now refer to $arg1
* Pass in all view variables + locally scoped variables:
<?php
$vars = $this->getVars();
$vars['arg1'] = 'value1';
echo $this->partial('template1', $vars);
--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
没有评论:
发表评论