Thanks for the answer :)

Actually I simplified the example. The real case, the admin module builds an
Admin_Form_Page. Based on the request, the blog module can return a form
instance, but it's not allways the case. The form is a Blog_Form_Admin (for
example, but the admin module doesn't know this for sure).
The Blog_Form_Admin might get filled with data A or data B, based on the
request (or even remains empty).
All the logic (wheter or not to return a form and if so, which data is used
to fill the form) is imho a piece of logic for the Blog module.

But eventually the Blog_Form_Admin needs to be placed as a subform in the
Admin_Form_Page, which causes all the troubles.

Regards, Jurian

2009/12/3 Diego Potapczuk <[email protected]>

> I didn´t understand it very well, but here are some tips that maybe help
> you.
>
> Dont´t build Forms inside controllers, make a separated class extending
> Zend_Form to define it, then use it in the controllers. If you need to
> construct it with some data, you can make a method in the Form class to do
> it.
>
> Example to ilustrate:
>
> Form
>
> <?php
>>
>> class Blog_Form_Post extends Zend_Form {
>>     public function init()
>>     {
>>         $this->setMethod('post');
>>
>>         $id = $this->createElement('hidden','idPost');
>>         $this->addelement($id);
>>
>>         $texto = $this->createElement('textarea','text');
>>         $texto->setLabel('Text:')
>>               ->setAttrib('size',50);
>>         $this->addelement($texto);
>>
>>         $salvar = $this->createElement('submit','salvar');
>>         $salvar->setLabel("Salvar")
>>                ->setIgnore(true);
>>         $this->addelement($salvar);
>>     }
>>
>>     public function setIdPost($id)
>>     {
>>         $this->getElement('idPost')->setValue($id);
>>     }
>> }
>>
>
> Controler
>
> public function editFormAction()
>> {
>>     $post = $this->getRequest()->getPost();
>>     $form = new Blog_Form_Post();
>>     $form->setIdPostValue($post['idPost']);
>>
>>     $this->view->form = $form;
>> }
>>
>
>
> Now you can use it anywhere, even outside Blog module
>
>
>
> ::: Diego Potapczuk
>
> »» Analista de sistemas
> »» Tel: (71) 3287-8343 / (71) 9144-3062
> »» http://www.diegoliveira.com.br
>
>
>
> On Wed, Dec 2, 2009 at 7:08 PM, Jurian Sluiman <[email protected]> wrote:
>
>> Hi all,
>> Is it possible to fetch the return value from a certain function inside
>> an
>> action controller?
>>
>> This is the use case: I have ad admin module and a specific controller.
>> This
>> controller builds a form to edit some data. The data might come from
>> another
>> modules, so I call the admin-controller from that module.
>> I want to have something like this (pseudo code):
>>
>> admin-module/controller-action:
>>
>>> $form = new Zend_Form;
>>
>> $subform = someMagicFunction('blog', 'admin', 'getForm');
>>
>> $form->addSubform($subform);
>>
>>
>> Is this possible to achieve? Currently I fetch the results with a custom
>> dispatcher, but that's imho an ugly hack...
>>
>> Regards, Jurian
>>
>
>

Reply via email to