本文介绍了在CodeIgniter中的模型中加载库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 为什么我的模型不加载加密库? class User_model extends Model { function User_model(){ parent :: Model(); $ this-> check_login(); } function check_login(){ $ this-> load-> library('encrypt'); $ email = $ this-> encrypt-> decode($ email); .... } } PHP错误:调用成员函数decode()on一个非对象在第X行 - 其中X是$ this-> encrypt-> decode($ email); = $ $ b 解决方案我是从构造函数内调用check_login,这是造成问题的原因。 解决方法是调用 $ this-> _assign_libraries(); $ $ b 感谢此代码签名论坛线程: http://codeigniter.com/forums/viewthread/145537/ Why won't my model load the encryption library?class User_model extends Model { function User_model() { parent::Model(); $this->check_login(); } function check_login() { $this->load->library('encrypt'); $email = $this->encrypt->decode($email); .... }}This giving me a PHP error: Call to a member function decode() on a non-object on line X -- where X is the $this->encrypt->decode($email); line?Edited to show that the problem was that check_login was called from the constructor 解决方案 I was calling check_login from within the constructor, and that was causing the problems.The solution is to call $this->_assign_libraries(); right after loading a library in a constructor.Thanks to this codeignitor forum thread:http://codeigniter.com/forums/viewthread/145537/ 这篇关于在CodeIgniter中的模型中加载库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-02 15:17