Newbie2016 Newbie2016 - 1 year ago 75
PHP Question

how to set a property in silm 3

I am trying to add a property in Slim 3 container, but when i var dump it shows me "Notice: Undefined property: Slim\App::$user". I know in Slim 2 it is :

return new User;


This will then show me all property in the user model container. However I am trying to achieve this in Slim 3.

I looked around the documents and found an add function but it returns an undefined property.

This is the code i tried:

return new User;

I know the User class does exist because i have tested that. I am stuck at this point and i am not sure what the method is to add a property to my container.

Answer Source

Its doesn't automatically add it as property when you register it on the DI container, you can just add it as a property with:

$app->user = new User;

Or with DI

$app->user = $app->container->get('user');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download