CodeIgniter Forums
About Entities declaration - 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: About Entities declaration (/showthread.php?tid=76275)



About Entities declaration - Majddar - 04-29-2020

Hello World (First message :p)

I followed the example of the documentation for the use of entities:
creation of the User.php file in the app/Entities folder with User Class definition extends Entity.
added protected line $returnType = 'App\Entities\User'; in the UserModel model

But when using $user = new App\Entities\User(); in the controller I have the error Class 'App\Controllers\App\Entities\User' not found. However, this is the line noted in the documentation https://codeigniter.com/user_guide/models/entities.html

I understand the logic so with
$user = new \App\Entities\User();
it's OK

and with
use App\Entities\User;
...
$user = new User();

But following the documentation in a way I think logical, I looked for a moment why it didn't work.

Is it me who didn't understand, a problem in the documentation or in the functioning of the entities.


RE: About Entities declaration - jreklund - 04-29-2020

Hello Majddar,
I think you just may had some bad luck, due to the fact the documentation just got updated with that specific change. I saw it a couple of days ago in the development branch and now the change have made it to the official website.

There are still work being done to the userguide and eventually we will have found all typos, so please bear with us. :-)


RE: About Entities declaration - Majddar - 04-29-2020

No problem,
I was not sure how it worked and I did not know if the error came from me.
I have written documentation in the past, and I understand you completely.
Good luck to all and thank you very much.


RE: About Entities declaration - HTLove - 05-03-2020

You can use: $user = new \App\Entities\User();
In the UserModel, you can change $returnType = 'App\Entities\User'; to $returnType = '\App\Entities\User';
thank


RE: About Entities declaration - Majddar - 05-04-2020

Thx for this precision, jreklund've made correction in documentation for the missing \ before App