如何在 CodeIgniter 中跨多个模型组织一组操作?
我有很多模型,比如说“Model1”、“Model2”和“Model3”。我有一组特定的操作,通常从每个模型中调用一个方法并按顺序执行它们:
$user_info = $this->load->User_model->load( $user_id );
$this->load->Car_model->deleteCarsForUser( $user_info );
$this->load->Message_model->sendMessage( "Car deleted", $user_info );
毫无疑问,这是一个粗略的示例。但这三个步骤在多个地方被多个控制器方法调用。无论如何,我是否可以将它们封装到一个声明中?
I have many models, let's say "Model1", "Model2" and "Model3". I have a certain group of actions that usually calls a method from each of these models and executes them in order:
$user_info = $this->load->User_model->load( $user_id );
$this->load->Car_model->deleteCarsForUser( $user_info );
$this->load->Message_model->sendMessage( "Car deleted", $user_info );
That's a crude sample, no doubt. But these three steps are called in several places by several controller methods. Is there anyway for me to encapsulate them into one statement somehow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个库来处理它和其他相关功能。
http://ellislab.com/codeigniter/user_guide/general/creating_libraries.html
You could make a library to handle it and other related functions.
http://ellislab.com/codeigniter/user_guide/general/creating_libraries.html