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`;
Related
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.
I have an error with the following file, and specifically, I assume, the following line:
$data['events'] = $this->homes->get_events();
The error is:
Message: Undefined property: CI_Loader::$homes
I am in the controller file, where I assume the problem is.
File name: /application/controllers/Home.php
$data['events'] = $this->homes->get_events(); <?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function _construct()
{
parent::_construct();
$this->load->model('homes');
}
public function index()
{
$data['events'] = $this->homes->get_events();
$this->load->view('template/header.php');
$this->load->view('home/index.php', $data);
$this->load->view('template/footer.php');
}
}
There is a model file at models/Homes
We tried changing the name of the model file to 'homes' (lower case) and also the code to 'Homes', but the same error persisted.
Specifically the error on running the url is:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$homes
Filename: controllers/Home.php
Line Number: 15
Backtrace:
File: public_html/anchor/application/controllers/Home.php
Line: 15
Function: _error_handler
File: /public_html/anchor/index.php
Line: 315
Function: require_once
I have controller named "Error" in codeigniter "application/controllers/Error.php".
I used this controller to override default 404 error page through routes.
$route['404_override'] = 'myerror';
But on 404 error occurrence I am getting following error.
A PHP Error was encountered
Severity: Warning
Message: call_user_func_array() expects parameter 1 to be a valid callback, class 'Error' does not have a method 'index'
Filename: core/CodeIgniter.php
Line Number: 514
Backtrace:
File: C:\xampp\htdocs\ci-app\index.php
Line: 292
Function: require_once
But when I rename Error controller to another, it works.
Please help.
You need to change your controller and file name to myerror like,
<?php
//application/controllers/Myerror.php
class Myerror extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->output->set_status_header('404');
$data['content'] = 'error_404'; // Let View name
$this->load->view('index',$data);// loading view
}
}
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');
I have error, please help
A PHP Error was encountered
Severity: Notice
Message: Undefined property: User::$user_model
Filename: controllers/user.php
Line Number: 15
Backtrace:
File: C:\wamp\www\apcodeigniter\application\controllers\user.php Line:
15 Function: _error_handler
File: C:\wamp\www\apcodeigniter\index.php Line: 292 Function:
require_once
Line 15 is: public function get()
public function get()
{
$this->user_model->get();
}
You haven't loaded the model yet.
Try changing the get method in User controller to -
public function get()
{
$this->load->model('user_model');
$this->user_model->get();
}
What I usually do in controllers, which are going to be depedent on that model, and each method would require some method of that model.
/*
* Load the model in the controller's constructor
*/
class User extends CI_Controller
{
function __construct()
{
parent::_construct(); //This is important if you're adding a constructor in the Controller, so that it can properly initialize the scope of CI_Controller in itselves
$this->load->model(array('user_model'));
}
public function get() //public here really isn't necessary, but kept it for understanding
{
$this->user_model->get();
}
}
Hope this helps.