Codeigniter 3 - Unable to locate the model you have specified - php

I am aware of the other questions on the platform for this issue however I am having a very unusual issue with this.
I have a model Company_Model.php which is being autoloaded in the autoload.php and the Class is built like this:
Class Company_Model extends CI_Model {
function __construct()
{
parent::__construct();
}
public function foo()
{
echo 'bar';
}
}
However I am still getting this error when I load the page:
I am running on Apache 2, PHP 5.5.9 on Ubuntu 14.04, I cannot find an error log for this issue and now I am baffled, any help would be gratefully recieved.
I have check the uppercasing and all of the other tips from StackOverflow but still no joy.
Edit
Auto load code
$autoload['model'] = array('company_model');

When you use codeigniter 3 you have to make sure your class names and file names only have the first letter upper case as explained here
Class Naming Style Guide
Filename Style Guide
<?php
class Company_model extends CI_Model {
}
And file name then should be Company_model.php
$autoload['model'] = array('company_model');
If in sub folder
models > sub folder > Company_model.php
$autoload['model'] = array('subfolder/company_model');
If need to call it on controller only
$this->load->model('company_model');
$this->company_model->function();
Sub folder
$this->load->model('subfolder/company_model');
$this->company_model->function();

Make sure your class name and file name should be same and first Letter should be Capital
Example
class Login extends CI_Model{
//some code
}
above code, you can see the class Login first letter is capital.same name you have save of your model file name like Login.php in the model directory of your project folder

Try Changing the class name Company_Model to Company_model and also change your file name Company_Model.php to company_model.php

Related

CodeIgniter Model Locate Issue After Upload to server

After Hosting Php codeignitor website I Got a Error "Unable to locate the model you have specified: Common_model"
But Its Works in my local server
How I can solve this issue
I already change First letter of the model class name capitalized but no result
my model class
class Common_model extends CI_Model
{
}
and controller is
<?php
class Show extends CI_Controller
{ var $pageLimit = 6;
public function __construct()
{
parent::__construct();
$this->load->library('ion_auth');
$this->load->model('common/Common_model');
$this->load->helper('url');
$this->load->helper('form');
$this->load->helper('custom');
}
}
If you are are using Codeignitor 3 than make sure you file name also start with capital letter as:
Common_model.php
It's recommended to use your models inside the model folder not model/anyfolder
Codeignitor 3 Change Log User Manual
I hope Your model file structure is like
application
model
common
Common_model.php
File name should be Common_model.php.
Load in Controller should be
$this->load->model('common_model');
I always load it with the name only, this way
$this->load->model('Common_model');
Always the controller is on the same module (if you are using modules)

Codeigniter Doctrine is not working with underscore( _ ) class name

Hello guys i created Entity folder inside application/model/. In Entity folder i created file Mj_user.php and give class name as same Mj_user.
but when i try to access that class using
$User= new Entity\Mj_user;
it's giving me error
Fatal error: Class 'Entity\Mj_user' not found in C:\xampp\htdocs\project\application\controllers\user.php on line 15
what should i do Please help me..but when i remove Mj_ then put only file name as User.php. Its working properly..Please help me
When creating a new class you have to be careful, the name of the class must be:
class Mj_user extends CI_Model {
function __contruct()
{
partent::construct();
}
}
The file must be mj_user.php and for using this model you must load it before start using it
it can be preloaded for all in the configuration or you can load it whenever you need it like this
$this->load->view('mj_user');
And in the error seems that is looking for a file called user.php and should be mj_user.php

parent controll in Codeigniter 2.2 project not found

In my CI 2.2 project I want to make my parent controll with app's common functionality for use in all app and for this I create file :
application/libraries/N_Controller.php :
<?php
class N_Controller extends Controller
{
public function __construct()
{
parent::__construct();
}
But on first attempt to use it in file
application/controllers/admin/admin.php
<?php
class Admin extends N_Controller
{
public function __construct()
{
parent::__construct();
I got error:
PHP Fatal error: Class 'N_Controller' not found in /controllers/admin/admin.php on line 3, referer: http://local-ci22.com/admin/hostel/edit/15
I tried to add in application/config/autoload.php file :
$autoload['libraries'] = array( 'AppSmarty', 'AppUtils', 'N_Controller');
But it did not help. Which is the correct way ?
if you want to extend the functionality of a system class. you need to follow this recomendations.
place your extended class in /application/core, be sure that you name it exactly like the name and casing of the class created.
your class should extend from CI_Model or CI_Controller, depending on your needs.
wherever you implement your new class, be sure that you honor the same name casing from your extended class.
you should have configured the $config['subclass_prefix'] on /application/config/config.php. let's say in your case with the value 'N_'
what i can see from your code, you are not extending from CI_Controller and your path seems wrong.
Informative note: the /application/library is used to place classes and libraries from 3rd parties that won't fit into CI schemas.

Codeigniter Can't Find My_Model

Very frustrating -
When I'm developing locally everything works perfect . I then started testing on my host (GoDaddy) for the first time and I get the error
Fatal error: Class 'MY_Model' not found in /home/content/49/12220009/html/application/models/user_model.php on line 3
The code is very basic -
User_model.php
class User_model extends MY_Model {
protected $_table;
public function __construct() {
parent::__construct();
$this->_table = "user";
}
MY_Model.php (application/core/My_Model.php)
class MY_Model extends CI_Model
{
public function __construct() {
echo "in my model ctor";
parent::__construct();
}
And it all starts with a controller loading User_model as expected -
$this->load->model('user_model');
Any thoughts on why this would work locally but not on my host , or how to solve it in other words?
it is definitely a case-sensitivity issue; what you should do is follow these two steps
1.follow these conventions and you are good to go
class Model_name extends CI_Model
Model_name is the name of your class... Class names must have the first letter capitalized with the rest of the name lowercase
and then the file name should be in lower case like this
application/models/model_name.php
This also happened to me:
on Linux system ,it show the error you specify while on window it was fine.
this is because Linux is case sensitivity .
what i did?;
I rename the file from /core/MY_model to /core/MY_Model.
and ,then it solved my problem .
CodeIgniter 3 solution
The class name and the class filename must have an uppercase first character.
Starting with CodeIgniter 3.0, all class filenames (libraries,
drivers, controllers and models) must be named in a Ucfirst-like
manner or in other words - they must start with a capital letter.
For example, if you have the following library file:
application/libraries/mylibrary.php
… then you’ll have to rename it to:
application/libraries/Mylibrary.php

Production Error:Unable to locate the model you have specified

I am developing on codeigniter from last two months. But when I pushed my code to Web hosting site today, I am getting this error. Few things I have checked 100 times:
Controller method says $this->load->model('myModel');
In the model folder I have myModel.php
It starts with
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');<br/>
class MyModel extends CI_Model {
public function __construct()
{
parent::__construct();
}
I have checked spelling mistakes or some typo but everything seems to be fine.
A name of model should be lower case: mymodel_model.php on /application/models/ directory.
The mymodel_model.php contains:
class Mymodel_model extends CI_Model {
public function __construct()
{
parent::__construct();
}
And call it as:
$this->load->model('mymodel');
A _model string MUST be on:
filename of model mymodel_model.php
a class name with first uppercase name class Mymodel_model
Full example on Codeigniter manual: http://ellislab.com/codeigniter/user-guide/general/models.html
make the name of your model lower case all ex: "mymodel.php" and then in autoload.php just put this code $autoload['libraries'] = array('session','database'); Just get the parent construct int the model and make it simplier like this code.
<?php
class MyModel extends CI_Model
{
public function functionName()
{
}
}
Model filename should be all lowercase. #ddjikic's reply was correct and _model is not necessary.
I am using codeigniter 3.0.0 and I just faced same issue in my application when I hosted it to the production site. I salved it using the capitalizing the filename (first letter) as mentioned in error.
The Capitalize and lowercase filenames are dependent on different hosting servers.
I just made the filename's first letter capital and it works fine for me. I don't know what settings my hosting server have. but it worked for me.
You can also try, hope it can salve your error.
Example:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Enquiry_model extends CI_Model
{
}
As in above example my filename was enquiry_model.php when it gives me error.
But later I renamed it to Enquiry_model.php and it salved my error.

Categories