Codeigniter - autoloading models with aliases
yes you can create same alias in in autoload pass as an array try but not possiable with only alias you can create same alias as auto loading time.
$autoload['model'] = array(array('users_model', 'users'), array('an_model', 'an'), 'other_model');
or try
$autoload['model'] = array(array('users_model', 'users', FALSE));
For more :- https://github.com/EllisLab/CodeIgniter/issues/2117
For CodeIgniter 2.x this is not possible in autoloading, but you can do it by extending the default controller. Create a file MY_Controller.php
in the application/core
directory, with this code:
<?phpclass MY_Controller extends CI_Controller{ function __construct() { parent::__construct(); $this->load->model('Example_model', 'alias'); }}
Of course, replace Example_model
and alias
with your appropriate model and desired alias.
Then change your controllers to extend MY_Controller
instead of CI_Controller
. Now you can use $this->alias->whatever()
in any Controller.