0x52616A657368
0x52616A657368

Reputation: 378

Unable to use include function a file in Codeigniter

A PHP Error was encountered

Severity: Warning

Message: include(../models/loginDao.php): failed to open stream: No such file or directory

Filename: controllers/LoginCon.php

Line Number: 3

Backtrace:

File: C:\wamp\www\xxx\CodeIgniter-3.0.0\application\controllers\LoginCon.php Line: 3 Function: _error_handler

File: C:\wamp\www\xxx\CodeIgniter-3.0.0\application\controllers\LoginCon.php Line: 3 Function: include

File: C:\wamp\www\xxx\CodeIgniter-3.0.0\index.php Line: 292 Function: require_once

But file named loginDao.php existed, in that path specified. Please help me out as I am new to CodeIgniter

Upvotes: 0

Views: 2012

Answers (1)

user4419336
user4419336

Reputation:

The loading of codeigniter models & controllers, should only have first letter of class and file name upper case

Controller

CodeIgniter User Guide Controllers

File name: Logincon.php

<?php 

class Logincon extends CI_Controller {

    public function __construct() {
       parent::__construct();
       $this->load->model('logindao');
    }


    public function index() {
        $data['something'] = $this->logindao->get_somthing();

        $this->load->view('login', $data);
    }

}

Model

CodeIgniter Userguide Models

File name: Logindao.php

<?php

class Logindao extends CI_Model {
    public function get_somthing() {
       // Some model code
    }
}

Your include method: I would not load models this way.

<?php

include APPPATH . 'models/Logindao.php';

// Or

include FCPATH . `application/models/Logindao.php`;

Upvotes: 0

Related Questions