$this->load->model() not working in CodeIgniter

前端 未结 5 1678
攒了一身酷
攒了一身酷 2021-01-13 19:52

I\'m using CodeIgniter 2.1.2 and here\'s my situation right now. I have a model named math.php in C:\\wamp\\www\\cr8v\\application\\models. I am trying to load

相关标签:
5条回答
  • 2021-01-13 20:12

    Well, it should always be noted that function name should not be replicated with controller or model name such as below;

    <?php
      class Abc extends CI_Controller{
    
    public function abc(){} // this confused CI in loading   
    
    }
    

    this may be helpful for developers new to CI,

    0 讨论(0)
  • 2021-01-13 20:14

    The name needs to be the same in all places:

    Here:

    class Math_model extends CI_Model {
       // your model
    }
    

    Here:

    $this->load->model("math_model");
    

    When using it:

    $this->math_model->add();
    

    And: in your file system. So rename math.php to math_model.php and it will work.

    0 讨论(0)
  • 2021-01-13 20:16

    The question has been answered really and the problem was this:

     <?php
        class Math_model extends CI_Model(){
            //so on
            } 
     ?>
    

    ..it's the open and close parethesis after declaring the class.. it should be:

     <?php
        class Math_model extends CI_Model{
            //so on
            } 
     ?>
    

    thank you so much for those who responded

    0 讨论(0)
  • 2021-01-13 20:28

    The name of the file should be math_model.php and you should call it like this:

    echo $this->math_model->add();
    
    0 讨论(0)
  • 2021-01-13 20:31

    File name and model name should be same try this instead

    class Math_model extends CI_Model {
       // your code
    }
    

    and the file name should be Math_model.php

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