CakePHP: calling other Model functions

前端 未结 7 678
感动是毒
感动是毒 2020-12-31 10:04

How can i call, from a Model, a function present in another model? I would like not to repeat code.

7条回答
  •  暖寄归人
    2020-12-31 10:08

    no, you should use ClassRegistry like so:

        //MessagesController - in my send() method...
    
    $this->set('content', ClassRegistry::init('Content')->find('first', array(
            'conditions' => array('Content.id' => 3)
    
            )));
    

    NOTE:this is from my controller but I am pretty sure it works in model too.

提交回复
热议问题