CodeIgniter Forums
Model Access - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: Model Access (/showthread.php?tid=68236)



Model Access - nilam.dhok - 06-13-2017

Hello Everyone,

I'm auto loading some model classes and unable to access it from admin controller.

Admin controllers are not directly inside application/controllers structure. It's structure is like application/controllers/admin/<controller_name>

Where as models are on default path application/models/<model_name>

Please refer attached screenshot and suggest me a solution how can i access model inside this kind of controller folder structure?

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

EDIT : Right now Instead of loading model, I created object of the model & I was able to access model class methods in admin controller.
But my question remains same, If I want to use loaded models then how can I access it without creating any object?


RE: Model Access - InsiteFX - 06-14-2017

I suggest that you open ./system/core/Codeigniter.php and see how things are loaded.


RE: Model Access - nilam.dhok - 06-14-2017

(06-14-2017, 02:54 AM)InsiteFX Wrote: I suggest that you open ./system/core/Codeigniter.php and see how things are loaded.

I have auto-loaded it correctly, there is no issue with auto-loading.

/*
| -------------------------------------------------------------------
|  Auto-load Models
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['model'] = array('first_model', 'second_model');
|
| You can also supply an alternative model name to be assigned
| in the controller:
|
| $autoload['model'] = array('first_model' => 'first');
*/
$autoload['model'] = array('Helper_model'=>'lib','login_model'=>'login');


RE: Model Access - nilam.dhok - 06-14-2017

Please some one suggest me solution asap. Every help is appreciated.


RE: Model Access - Martin7483 - 06-15-2017

If the page is loading without any problems you should be able to access it via

PHP Code:
// Your helper model
$this->lib->some_method();

// Your login model
$this->login->some_method(); 

Show us the code of your Admin Controller.
Does it have it's own constructor? Are you extending from a MY_Controller?


RE: Model Access - nilam.dhok - 06-19-2017

It worked when I tied to load model files like - "../models/<model_file_name>"

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

$this->load->model('../models/Helper_model', 'lib');
$this->load->model('../models/Login_model', 'login');
}

From controller which was inside application/controllers/admin/<controller_name>