|
I know the new form stuff is almost ready but I'm currently using beta 3 with the current forms and have an issue with the ViewScript decorator.
I have registered custom view helpers with Zend\View\HelperLoader which override a couple of the default ones (FormRadio and FormMultiCheckbox) and they work fine when using the FormElements decorator. The problem arises when using the ViewScript decorator, it seems to be using the default set of view helpers, i.e. a new instance of Zend\View\HelperLoader instead of the one registered in the DI. 'Zend\Form\Form' => array( 'parameters' => array( 'view' => 'Zend\View\Renderer\PhpRenderer', ), ), 'Zend\View\HelperLoader' => array( 'parameters' => array( 'map' => array( 'formradio' => 'MyNamespace\Zend\View\Helper\FormRadio', 'formmulticheckbox' => 'MyNamespace\Zend\View\Helper\FormMultiCheckbox', ), ), ), |
|
Administrator
|
-- macest <[hidden email]> wrote
(on Thursday, 10 May 2012, 08:43 AM -0700): > I know the new form stuff is almost ready but I'm currently using beta 3 with > the current forms and have an issue with the ViewScript decorator. > > I have registered custom view helpers with Zend\View\HelperLoader which > override a couple of the default ones (FormRadio and FormMultiCheckbox) and > they work fine when using the FormElements decorator. The problem arises > when using the ViewScript decorator, it seems to be using the default set of > view helpers, i.e. a new instance of Zend\View\HelperLoader instead of the > one registered in the DI. How are you rendering the form and/or elements, exactly? You should be doing at least one of the following: * $form->setView($this) * $form->render($this) These ensure that the renderer is pushed down into the tree; otherwise, an instance will be lazy-loaded for you -- which would cause you to lose any configuration you previously had. -- Matthew Weier O'Phinney Project Lead | [hidden email] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc -- List: [hidden email] Info: http://framework.zend.com/archives Unsubscribe: [hidden email] |
|
Hi,
You can do something like that in your controller $form = new myForm(); $form->setView($this->getLocator()->get('view')); Regards, 2012/5/15 Matthew Weier O'Phinney <[hidden email]> > -- macest <[hidden email]> wrote > (on Thursday, 10 May 2012, 08:43 AM -0700): > > I know the new form stuff is almost ready but I'm currently using beta 3 > with > > the current forms and have an issue with the ViewScript decorator. > > > > I have registered custom view helpers with Zend\View\HelperLoader which > > override a couple of the default ones (FormRadio and FormMultiCheckbox) > and > > they work fine when using the FormElements decorator. The problem arises > > when using the ViewScript decorator, it seems to be using the default > set of > > view helpers, i.e. a new instance of Zend\View\HelperLoader instead of > the > > one registered in the DI. > > How are you rendering the form and/or elements, exactly? > > You should be doing at least one of the following: > > * $form->setView($this) > * $form->render($this) > > These ensure that the renderer is pushed down into the tree; otherwise, > an instance will be lazy-loaded for you -- which would cause you to lose > any configuration you previously had. > > -- > Matthew Weier O'Phinney > Project Lead | [hidden email] > Zend Framework | http://framework.zend.com/ > PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc > > -- > List: [hidden email] > Info: http://framework.zend.com/archives > Unsubscribe: [hidden email] > > > -- Pierre RAMBAUD - I N S T A N T | L U X E - 40 rue d'Aboukir - 75002 Paris - France Web : www.instantluxe.com |
|
In reply to this post by weierophinney
I am injecting the view renderer into the base form class via DI: 'Zend\Form\Form' => array( 'parameters' => array( 'view' => 'Zend\View\Renderer\PhpRenderer', ), ), All my forms are injected into service classes via the DI, e.g. 'alias' => array( 'my-service' => 'MyModule\Service\MyService', ), 'my-service' => array( 'parameters' => array( 'myForm' => 'MyModule\Form\MyForm', ), ), And an example of the form in the service class:
namespace MyModule\Service;
use MyModule\Form\MyForm;
class MyService
{
protected $myForm;
public function setMyForm( MyForm $myForm )
{
$this->myForm = $myForm;
}
public function getMyForm()
{
return $this->myForm;
}
}
|
| Powered by Nabble | Edit this page |
