0

I've got a partial that I'm using in a Symfony 1.4 admin generated module but I have some logic that I would prefer to keep in my action. Is there anyway to access action vars in the partial? In a regular template (ie: non admin generated), I could simply declare my var in my action as $this->myVar and then access it from within my template as $myVar, but is there any way to do this in an admin partial?

I've tried declaring it in my preExecute() method but the var is undefined in my partial template.

Am I doing something wrong, or is my only choice to use a component instead of a partial?

4

2 回答 2

1

When you call this partial try to put the variable as a second parameter (or array of parameters) in the include_partial().

于 2013-01-03T16:42:01.993 回答
1

Partials and components don't have automatic access to action variables. They only see variables which are explicitly passed to them. In an admin generator module they usually get some useful parameters (e.g. the current object, helper object, configuration, form) but it depends on the current place of invocation (you can see the generated templates in the cache directory to find out which parameters they get). Partials also have access some global objects (e.g. request, user, response,...) which are available in every template file. You can use e.g. request attributes or slots:

// in an action
$this->getResponse()->setSlot('my_slot', $myVariable);

// in a partial
<?php include_slot('my_slot'); ?>
// or
<?php $my_variable = get_slot('my_slot'); ?>

But I think using a component is a better idea.

于 2013-01-03T22:32:29.980 回答