开发者

CodeIgniter Model Call to Model

开发者 https://www.devze.com 2023-03-26 10:45 出处:网络
Im using CodeIgniter 2.0.2 and I noticed while calling a Model from within a Model, you dont need to load it.

Im using CodeIgniter 2.0.2 and I noticed while calling a Model from within a Model, you dont need to load it.

F开发者_StackOverflowor instance, in a Controller you need to write

$this->load->model('my_model');
$this->my_model->my_function();

But in a Model it can load just like this

$this->my_model->my_function();

Should i avoid writing my code like this, or is this safe?


I would avoid writing my code like this, but for a different reason.

Models are generally loaded from controllers, so it seems strange that you would need one model to call another one. Are you sure that there is not a better way to structure your code, such as having a model base class or using a helper for common functionality?

0

精彩评论

暂无评论...
验证码 换一张
取 消