Unable to locate the model you have specified: users - php

When I am going to run my file, it shows an error like this,
Unable to locate the model you have specified: users
I have controller, models and view in Modules folder and I think its a HMVC structure.
What is wrong with it?

Load the model before you use it.
$this->load->model('users');
Also make sure that your model starts like:
class Users extends CI_Model{ }
CI version 2.1.4

Related

Session.php class is not able to load properly

I am working on PHP in Code-igniter. I want to call function of one controller on another controller. I have tried following code for that-
$this->load->library('../controllers/Benchmarking');
$this->Benchmarking->init_benchmark();
But after doing this I got an error as unable to locate the specified class:session.php
(Here, benchmarking is my controller and init_benchmark is that function which I want to call)
Can anyone help me, please?
You cannot call a function of a controller from another controller. CI won't allow it.
If you need the user to "move" from a controller to another, your best bet is to set session flashdata with all the data you need to pass from one controller to the other and then use a simple redirect.
$this->session->set_flashdata('handoff_data');
redirect('second_controller/function');
There are other ways, some more powerful, some more complicated, but this is by far the simplest one
please check your class name and extends properly. and create a common controller in your core folder like
class MY_Controller extends CI_Controller {
}
and call this controller in another controller's extends.

Codeigniter loading model from different subfolder

I'm facing one weird problem with my Codeigniter project.
I have two model files in the following paths:
models/public/Dish_model.php
models/admin/Dish_model.php
For front-end and back-end models respectively.
In the controller which is in the following path:
controllers/admin/Dish.php
I'm trying to load the admin area model file using:
$this->load->model('admin/dish_model');
But it is loading the public model file.
Even if I comment this line out the public model file still gets loaded.
This all happened suddenly it was working fine before and I haven't changed any of the mentioned files recently.
Any help?
In case anyone else encounter the same issue.
In my case and after carefully following the execution path of the controller I found that the other model was being loaded by a library in the autoload list.
Removing that library from the autoload array fixed the problem.
to call/load a model from its subdirectory or subfolder.
models/public/Dish_model.php
let's say in Dish_model
class Dish_model extends CI_Model{
public function __construct(){
parent::__construct();
}
public function the_method(){
return 'return value';
}
}
models it's a native ci model directory and public it's a subdirectory. so to load the Dish_model do this on controller
$this->load->model('public/Dish_model','DModel');
the DModel it is like an alias.
so to call the model from the controller is
echo $this->DModel->the_method();
and it will return return value
hope its help.

getting error when adding a class in codeigniter

I am using a Facedtector class for my work. I added the class in my Codeigniter libraries folder and just called from my controller class. In my controller I also loaded the class but run time it is showing following error:
An Error Was Encountered
Non-existent class: FaceDetector
Please anyone can help me about this.
Thanks
Add your class file inside you library folder of your main application folder.
And then you can use the auto load function of codeigniter
application/config/autoload.php
at the above location and then you can access the class directly or other way of using this use
$this->load->library('Your_Class_Name', 'Path\to\your\class');
This way you can access your class in codeigniter
You can follow below link for autoload of a class library.
https://ellislab.com/codeigniter/user-guide/general/autoloader.html

Accessing other model file within another model file

I am trying to create an class inside the model directory. This class(eg:- Admin) exposes only the methods which makes sense to the controller.
The Admin class will do all the joins and stuffs internally on tables(using ORM) and prepares data which can be readily consumed by the controller.
I have created 15 files in the model directory each of them representing a table in my database using the ORM method.
Now I want to create to create an instance of table within the Admin classes' get_All() method. I have tried to use Kohana::factory() which was unavailable in my Admin class. I tried to create the instance using the 'new', but it ended in an error which says that the specified class is not found.
My class definition for Admin is as follows
<?php defined('SYSPATH') or die('No direct script access.');
class Model_Admin {
public function get_All()
{
$PD = new Model_PayPalData;
echo 'Success';
}
}
The error is:
ErrorException [ Fatal Error ]: Class 'Model_PayPalData' not found
APPPATH/classes/Model/admin.php
Please advice on how to deal with this situation.
Thanks for your attention
Seem like your class is not loaded. You can check this by viewing the declared classes
get_declared_classes();
If it is't there, make sure to include it, or add it to the Models directory, if needed without extending the ORM class.

Missing Controller - Cake PHP (New installation)

I have installed cakephp in document root folder and renamed it to todo. So the complete path is (C:\localhost\todo). I am able to run the index.php perfectly fine (all tabs are green).
I created the 'todo' example application from the book 'Beginning CAKE PHP - Novoice to Professional'. I keep getting the error 'MISSING CONTROLLER' even though I have the items_controller.php file. I am thinking for some reason the application does not know where the controller file is present.
The complete error is :
Missing Controller Error: ItemsController could not be found. Error:
Create the class ItemsController below in file:
app\Controller\ItemsController.php
<?php
class ItemsController extends AppController {
}
I have .htacess and index.php files in respective folder
Can someone please help.
Controller class names are plural, CamelCased, and end in Controller. So your controller name should be ItemsController.php not items_controller.php. See here for more info on Controllers.
class ItemsController extends AppController {
//class code here
}

Categories