Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common_Model.php exists, but doesn't declare class Common_Model

I tried checking all the names. It is working fine in php 5.3 but not working in php 5.5

An uncaught Exception was encountered

Type: RuntimeException

Message: C:\xampp\htdocs\project\application\models/Common_Model.php exists, but doesn't declare class Common_Model

Filename: C:\xampp\htdocs\project\system\core\Loader.php

Line Number: 306

Backtrace:

File: C:\xampp\htdocs\project\application\controllers\Auth.php Line: 7 Function: __construct

File: C:\xampp\htdocs\project\index.php Line: 292 Function: require_once

In the message, I can see an unexpected backslash in front of Common_Model.php. Message: C:\xampp\htdocs\project\application\models/Common_Model.php exists, but doesn't declare class Common_Model

Common_Model.php contains:

<? if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Common_Model extends CI_Model {


        public function __construct()
        {
                // Call the CI_Model constructor
                parent::__construct();
        }
        .
        .
        .
        .

EDIT

I just changed Common_Model.php to Common_model.php and still getting the same error

An uncaught Exception was encountered

Type: RuntimeException

Message: C:\xampp\htdocs\project\application\models/Common_model.php exists, but doesn't declare class Common_model

Filename: C:\xampp\htdocs\project\system\core\Loader.php

Line Number: 306

Backtrace:

File: C:\xampp\htdocs\project\application\controllers\Auth.php Line: 7 Function: __construct

File: C:\xampp\htdocs\project\index.php Line: 292 Function: require_once

like image 547
LIGHT Avatar asked Jan 04 '16 12:01

LIGHT


2 Answers

Your web server doesn't like php shorthand operator. Just change <? to <?php and it should be all good.

like image 191
Bishnu Paudel Avatar answered Oct 05 '22 18:10

Bishnu Paudel


Try this

file name should be Common_model.php

and inside that

<?php

    if (!defined('BASEPATH'))
        exit('No direct script access allowed');

    class Common_model extends CI_Model {

        public function __construct()
        {
            parent::__construct();
        }

        public function getUser()
        {
            # Your query goes here
        }

    }

In Controller

$this->load->model('Common_model'); # Load Model
$result = $this->Common_model->getUser(); # Access the model function
like image 43
Abdulla Nilam Avatar answered Oct 05 '22 18:10

Abdulla Nilam