简体   繁体   中英

Codeigniter not loading model constructor

Update :

parent::__construct() or die("error1");

in the constructor of the person model produces "error1".

Where am I doing it wrong ?

I am beginning to learn CodeIgniter 2.2

I have a person_model.php file :

<?php 
class Person_model extends CI_Model{

function __construct()
{
    parent::__construct();      
    $this->load->database();

}

public function get_person($name=''){

    if ($name==='') {
        $query = $this->db->get('Person');  
        return $query->result_array();
    }

    $query = $this->db->get_where('Person',array('name' => $name));
    retrun $query->row_array();

    }
}



?>

My controller has a function

public function view(){
    if (!file_exists(APPPATH.'/views/pages/view.php')) {
        show_404();
    }
    print_r("begin");
    $this->load->model('person_model') or die("Same problem");
    print_r("end");
    $data['title'] = ucfirst("view");
    $data['persons'] = $this->person_model->get_person();

    $this->load->view('templates/header', $data);
    $this->load->view('pages/view', $data);
    $this->load->view('templates/footer', $data);
}

When I load it, I get 500 server error in console and the word begin

My CI logs show this :

DEBUG - 13-03-2017 12:33:57 --> Config Class Initialized
DEBUG - 13-03-2017 12:33:57 --> Hooks Class Initialized
DEBUG - 13-03-2017 12:33:57 --> Utf8 Class Initialized
DEBUG - 13-03-2017 12:33:57 --> UTF-8 Support Enabled
DEBUG - 13-03-2017 12:33:57 --> URI Class Initialized
DEBUG - 13-03-2017 12:33:57 --> Router Class Initialized
DEBUG - 13-03-2017 12:33:57 --> Output Class Initialized
DEBUG - 13-03-2017 12:33:57 --> Security Class Initialized
DEBUG - 13-03-2017 12:33:57 --> Input Class Initialized
DEBUG - 13-03-2017 12:33:57 --> CRSF cookie Set
DEBUG - 13-03-2017 12:33:57 --> Global POST and COOKIE data sanitized
DEBUG - 13-03-2017 12:33:57 --> Language Class Initialized
DEBUG - 13-03-2017 12:33:57 --> Loader Class Initialized
DEBUG - 13-03-2017 12:33:57 --> Controller Class Initialized
DEBUG - 13-03-2017 12:33:57 --> Model Class Initialized

So, I tried to focus on this piece in my controller :

print_r("begin");
$this->load->model('person_model') or die("Same problem");
print_r("end");

I see only begin and neither Same Problem nor end .

Where am I going wrong ? Why does my model not load properly

Update When I comment out the body of the function get_person, I get Same error displayed on browser

Update 2 I just checked my connection credentials in database.php file. It successfully connects to the database.

$this->load->model('person_model') to $this->load->model('Person_model') . Make sure the database connections are correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM