Welcome Guest, Not a member yet? Register   Sign In
About Entities declaration
#1

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.
Reply
#2

(This post was last modified: 04-29-2020, 10:43 AM by jreklund.)

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. :-)
Reply
#3

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.
Reply
#4

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

(This post was last modified: 05-04-2020, 01:17 AM by Majddar.)

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




Theme © iAndrew 2016 - Forum software by © MyBB