脚本宝典收集整理的这篇文章主要介绍了php – 如何在CodeIgniter中使用正确的面向对象的模型与构造函数?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$this->load->model('User'); $this->user->set_password($userID,$password);
但我想这样做:
$this->load->model('User'); $User = new User($userID); $User->set_password($password);
例如,如果我有一个有各种项目的购物清单,我想以这种方式使用PHP:
$this->load->model('List'); $this->load->model('Item'); $List = new List(); $items[] = new Item($itemName1,$itemPRice1); $items[] = new Item($itemName2,$itemPrice2); $List->add_items($items);
以这种方式处理PHP OO,CodeIgniter感到基本上破裂了.有谁有任何解决方案仍然可以在每个模型中使用超级对象?
require_once(APPPATH.'models/User.PHP'); $User = new User($userID);
或者,您可以依靠表级模型返回记录级别的模型:
$this->load->model('users_model'); // users (plural) is the table-level model $User = $this->users_model->get_user($userID);
同时,在users_model中
require_once(APPPATH.'models/User.PHP'); public function get_user($userID) { // get a record From the db // map record to model // return model }
以上是脚本宝典为你收集整理的php – 如何在CodeIgniter中使用正确的面向对象的模型与构造函数?全部内容,希望文章能够帮你解决php – 如何在CodeIgniter中使用正确的面向对象的模型与构造函数?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。