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

when i am working with localhost then everything is fine. But When i uploaded in hosting then its show error " Unable to locate the model you have specified"
An uncaught Exception was encountered Type: RuntimeException Message:
Unable to locate the model you have specified: Stock_model Filename:
/home/autorentbd/public_html/pharmacy/system/core/Loader.php Line
Number: 344
Backtrace:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Stock extends MY_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper("url");
$this->load->library("pagination");
$this->load->model('Stock/stock_model'); // My Model name is stock_model.php, is in module folder.
}
public function stock_list($data = NULL)
{
$data['title'] ='Medicine Stock List'; //data title
$data['stock_list'] = $this->stock_model->stock_list(); //call model function
$data['view_all'] = 'stock/stock_list'; //view file
$this->templates->version_one($data); //template
}
}
And My Model name: stock_model.php, My Class name is: Stock_model. all in under module folder.

Please check your file and class name, like if class name is Stock_model then load with "Stock_model" not stock_model. because some server are followed case sensitive.

CodeIgnitor 3 and further versions are case sensitive. You need to define controller as well as model name in first letter caps form. So you need to define your model as
$this->load->model('Stock/Stock_model');

Related

Codeignitor - An uncaught Exception was encountered

I am trying to fetch users by creating model and controller, I am just at initial stage of learning codeignitor, can anyone help?
controllers/Users.php:
<?php
class Users extends CI_Controller {
public function show(){
$this->load->model('user_model');
$result = $this->user_model->get_users();
foreach($result as $object){
echo $object->id;
}
}
}
?>
models/user_model.php:
<?php
class User_model extends CI_Model {
public function get_users(){
$this->db->get('users');
}
}
?>
Error:
An uncaught Exception was encountered
Type: RuntimeException
Message: Unable to locate the model you have specified: User_model
Filename: /home/sanadpjz/public_html/ci/system/core/Loader.php
Line Number: 314
Backtrace:
File: /home/sanadpjz/public_html/ci/application/controllers/Users.php
Line: 7
Function: model
File: /home/sanadpjz/public_html/ci/index.php
Line: 292
Function: require_once
URL vising:
example.com/ci/index.php/users/show
Database configured in config/config.php
Database table 'users' exists and has 1 record.
It is clear the loader is unable to find the model file and that is because you are naming the file wrongly. The file name should start with a capital letter as the class name, mentioned in CI3 documentation.
To fix your issue change your model file from
models/user_model.php
to
models/User_model.php.

CodeIgniter 404

I am new to codeIgnitor and keep getting the error 404, please advise where am I going wrong, below is my structure and pages.
database name: stoma_store_suppliers ,
Database fields: supplierid, supplier_name, supplier_phone
Models Page:_____________suppliers.php
<?php
Class Suppliers extends CI_Model
{
public function get_suppliers($supplierid) {
if($supplierid != FALSE) {
$query = $this->db->get_where('store_suppliers', array('supplierid' =>$supplierid));
return $query->row_array();
}
else {
return FALSE;
}
}
}
?>
Controllers Page__________
suppliers.php
<?php if (!defined('BASEPATH'))exit('No direct script access allowed');
class Suppliers extends CI_Controller {
public function show($supplierid) {
$this->load->model('suppliers');
$store_suppliers = $this->suppliers->get_suppliers($supplierid);
$data['supplier_name'] = $suppliers['supplier_name'];
$data['supplier_phone'] = $suppliers['supplier_phone'];
$this->load->view('index', $data);
}
}
?>
Views Page:
index.php
<?php print $supplier_name; ?>
<?php print $supplier_phone; ?>
Required things to access any page of codeigniter are:
First letter of controller file must be capital like Suppliers.php.
The first letter of the class definition must match the filename, e.g. for Suppliers.php it would be class Suppliers extends CI_Controller.
If a database is to be used, then the correct connection details must be set in the file config/database.php.
Below are the steps to access the any page created in the codeigniter.
Write your site domain followed by index.php, e.g. http://mysitedomain.com/index.php/suppliers
To remove the need for index.php in the URL add an .htaccess file at the root folder. Details here. In that case the URL will be
http://mysitedomain.com/. Now, domain name will get followed by controller name and the function to be accessed, e.g.
http://mysitedomain.com/suppliers/show
To pass arguments to a controller using the URL add them after the controller/function segments, e.g. http://mysitedomain.com/user/show/dede
If a controller has an index function - public function index(){ - it can be accessed two ways:
A) http://mysitedomain.com/suppliers/index
B) http://mysitedomain.com/suppliers
If /function/argument URI segments are not provided after controller name, codeigniter will call index() by default.

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
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`;

How to load the custom Model in Opencart

I have created the one custom Module in Opencart.
The details of that:
Controller: file named block.php in admin/controller/custom/block.php
View : file named block.tpl in admin/view/template/custom/block.tpl
Model : file named block.php in admin/model/custom/block.php
I have successfully configured permissions.
When I load this model in Controller means, I got the following error..
Fatal error: Call to a member function load() on a non-object in F:\xampp\htdocs\shirtrecipe\admin\controller\custom\block.php on line 11
Controller Code:
<?php
class ControllerCustomBlock extends Controller
{
public function index() {
$this->language->load('custom/block');
$this->model->load('custom/block'); /* doesnt load this model */
$this->data['breadcrumbs'] = array();
...
...
Model Code:
<?php
class ModelCustomBlock extends Model
{
public function get_demo_block() {
$sql = "select demo_block_img from oc_block where id=1";
$query = $this->db->query($sql);
return $query->row;
}
}
Change :
$this->model->load('custom/block');
To:
$this->load->model('custom/block');
Have a nice day !!

CI > Custom Base Controller cannot find Model

I have this file structure:
application
controllers
home.php
core
MY_Controller.php
models
users.php
These are the codes for each file:
home.php
class Home extends MY_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
echo "Hello World!";
}
}
MY_Controller.php
class MY_Controller extends CI_Controller {
var $user_model = null;
public function __construct() {
parent::__construct();
$this->user_model = new Users();
}
}
users.php
class Users extends CI_Model {
public function __construct() {
parent::__construct();
}
}
When I load the webpage on a browser, I get this error:
Fatal error: Class 'Users' not found in C:\%path%\application\core\MY_Controller.php on line 7.
Please help me make my custom base Controller to find my Model. Thank you!
NOTE:
The cases are as I have provided them (I heard there might be issues with case-sensitivities).
EDIT:
When I opened the log files, I found this.
ERROR - 2014-02-17 01:02:05 --> Severity: 8192 --> mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead C:\%path%\system\database\drivers\mysql\mysql_driver.php 91
Nevermind, I got it to work by either going in the config.php file and autoloading the model or by doing $this->load->model('Users');
Upper or lower case U seems to work.

Categories