Yes, you can do it! But instead of passing the Model object, you can
just pass the Model name and use $this->{$model}->save(); instead.

But where is the $model coming from? Add usually is being invoked due
to a HTML form being submitted to it! Are you suggesting to put the
model name into the form, not a good idea then.

Are your controllers only using one model and the models is named the
same as the controller (singular)? If that is so, you don't need to
pass the model, just take your controllers name and Inflect it into a
model name and use that!

Ok, just me throwing some ideas around :) Anyone else having good
thoughts on this issue?
Enjoy,
   John

On Feb 26, 9:27 am, sebb86 <[email protected]> wrote:
> Hello,
> i'd like to build a global-add function in the appController, so that
> all controllers can use it. is that possible?
>
> [App-Controller code:]
> function add($modell)
>         {
>                 if(!empty($this->data))
>                 {
>                         if($this->$modell->save($this->data))
>                         {
>                                 $this->Session->setFlash('saved');
>                                 $this->redirect(array('action' => 'index'));
>                         }
>       else
>       {
>         $this->Session->setFlash('not saved!');
>       }
>                 }
>         }
> [.........../]
>
> for example the current controller is named LocationsController:
> [code]
> var $modell = $this->Location;
> [..../]
>
> Thats what i tryed, but it dont works.
>
> Thanks if someone can help!

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 [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to