CodeIgniter Forums
Use new Model() - 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: Use new Model() (/showthread.php?tid=75025)



Use new Model() - Myster - 12-10-2019

Hello, first of all sorry for my English I am French.

I would like to know how is it possible to use models like this:

$ var = new Model ();

Because I do not like $ this-> model-> method

I prefer to work as I use class with bookstores, I do not want to get lost with the models

For example for my class User I do:
require_once (APPPATH. 'libraries/User.php');

$ user = new User ();

I would like to do that for models but when I do
require_once (APPPATH. 'models/AuthTable.php');

$ table = new AuthTable ();

I have this error:
Message: Class 'CI_Model' not found


Thank you


RE: Use new Model() - jreklund - 12-10-2019

Depending on how far along you are in your program, I would suggest you take a look at Codeigniter 4. It got support for namespaces and will autoload your models (and will work with new AuthTable(); )


RE: Use new Model() - InsiteFX - 12-10-2019

PHP Code:
$this->load->model('model_name');

$model = new model_name();