CodeIgniter: Can't load database from within a model

后端 未结 2 537
花落未央
花落未央 2021-01-22 02:50

I\'ve written a new model for my CodeIgniter framework. I\'m trying to load the database from within the constructor function, but I\'m getting the following error:



        
相关标签:
2条回答
  • 2021-01-22 03:13

    You're forgetting to call the parent constructor first. Something like:

    <?php
    
    class userdb extends Model {
    
    function __construct() {
    
        parent::Model();
    
        $this->load->database();
    
    }
    ?>
    
    0 讨论(0)
  • 2021-01-22 03:24

    I'm not sure if it would cause a problem or not, but Model names are supposed to have the first letter capitalized. http://ellislab.com/codeigniter/user-guide/general/models.html Jens is also correct that you need to call the parent constructor as well.

    0 讨论(0)
提交回复
热议问题