Wednesday, April 28, 2010

Re: Problem in using elements

That is what I wrote you! You want to show the edit form (from the
edit element) in another view, that is use it within another action
(controller/foo), am I correct?

So in your foo action, you have to make sure that the $this->data
array is filled with the same information as in the edit action -
which means that you have to fill is with the user data, just as you
did in the edit action.

[code]
function foo() {
// some other code
$this->data = $this->User->read(null, $id);
}
[/code]

This is because the form helper in your edit element reads the data to
use from the $this->data array!
Hope the above helps you on the way,
John


On Apr 27, 10:36 pm, sherzo <shahrzad.azimi...@gmail.com> wrote:
> Hi John
> Thanks for your quick reply!
> here is my  edit method :
>
> function edit($id = null) {
>                 if (!$id && empty($this->data)) {
>                         $this->Session->setFlash(__('Invalid User', true));
>                         $this->redirect(array('action'=>'login'));
>                 }
>                 if (!empty($this->data)) {
>                         if ($this->User->save($this->data)) {
>                                 $this->Session->setFlash(__('The User has been saved', true));
>                                 $this->redirect(array('action'=>'index'));
>                         } else {
>                                 $this->Session->setFlash(__('The User could not be saved. Please, try
> again.', true));
>                         }
>                 }
>                 if (empty($this->data)) {
>                         $this->data = $this->User->read(null, $id);
>                 }
>                 $coupons = $this->User->Coupon->find('list');
>                 $this->set(compact('coupons'));
>         }
>
> Actually it's working from edit view but not from edit element!!! I'm new in
> cakephp!! is there anything special with elements? aren't they working just
> like views?
>
> Thanks
> Sherry
[snip]

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: