CakePHP: calling other Model functions

前端 未结 7 631
感动是毒
感动是毒 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:28

    If you have a model function that you want to call from many models, the best approach is to abstract any references to the model name ($this->alias) and place the function in AppModel. Then it is accessible in any of your models.

    class AppModel extends Model{
        public function myFunction($options = array(){
           do some stuff with $this->alias;
        }
    }
    

提交回复
热议问题