If Hotelinfo belongsTo Hotel I imagine you have (or could have) a
hasOne (probably) association the other way. The point is that if you
have an association between the models they have automatic access to
each-other.
In Hotel you could go: $this->Hotelinfo->doSomething(); or even $this-
>Hotelinfo->Hotelinfomaster->doSomething();
Even if you don't wan to have the association necessary to "reach" the
model you need, you can always call
App::import('Model', 'Hotelinfo');
$Hotelinfo = new Hotelinfo();
In your case you would probably call for the creation of a Hotelinfo
record in your afterSave() in Hotel. You could move most of your
controller function into Hotelinfo and call it something descriptive
like createNewFor(). You would just have to adjust the references and
remove the redirects, flashes and requestActions.
/Martin
On Oct 9, 8:17 am, "Liebermann, Anja Carolin"
<[EMAIL PROTECTED]> wrote:
> Hello,
>
> I have read the article by Mark
> Story:http://mark-story.com/posts/view/reducing-requestaction-use-in-your-c...
>
> So now I want to use that. In some cases it works already very fine, but I am
> not sure if I can place an method in my model (which ist growing fatter day
> by day *g*) when it calls information from another model. (I use Cakephp 1.2
> RC3)
>
> E.g.:
>
> My Model Hotelinfo belongsTo Hotel and Hotelinfomaster.
>
> Now in my controller hotels_controller.php I have a function where when a
> hotel is added also a connected table entry of hotelinfo is added by getting
> the data from the Hotelinfomaster.
>
> At the moment I do it this way:
> $this->data =
> $this->Hotel->requestAction('hotelinfos/add/'.$hotelmaster_id.'/'.$this->Ho
> tel->id);
>
> That calls this funtion in hotelinfos_controller.php:
> function add($hotelmaster_id = null, $hotel_id = null) {
> if ($hotelmaster_id != null) {
> $this->Hotelinfo->create();
> //get data from Masterobject 'Hotelinfomaster'
> $this->data =
> $this->Hotelinfo->requestAction('hotelinfomasters/getHotelinfomaster/'.$hot
> elmaster_id);
> //do some data processing magic
> if ($this->Hotelinfo->save($this->data['Hotelinfo'])) {
> /*$this->Session->setFlash(__('The Hotelinfo wurde gespeichert', true));
> $this->redirect(array('action'=>'../hotels/edit/'.$hotelmaster_id));*/
> } else {
> $this->Session->setFlash(__('The Hotelinfo konnte nicht gespeichert
> werden. Bitte überprüfen Sie die Angaben.', true));
> }
> }
>
> }
>
> As you can see my function gets data from another model 'Hotelinfomaster'.
> Can I place such a function in my model hoteilinfo.php? If yes what would be
> the syntax to get the data from Hotelinfomaster?
>
> Thank you
>
> Anja
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---