Home  >  Q&A  >  body text

Guys, why can this code get the user name? ! !

I have a few questions:

1 Shouldn’t $user, the automatically loaded construct, be empty?

is to call $this->user->name in the hello method, so what you get is also empty.

Why is it written like this?

image.png

rainrain1686 days ago1101

reply all(3)I'll reply

  • 2020-02-12 13:38:59

    The parameter of the constructor method is required to be a userModel object. If this object has the attribute name, it can be $this->user->name.

    reply
    0
  • rain

    Yes

    rain · 2020-02-16 10:41:45
  • 小可耐

    小可耐2020-02-12 12:21:54

    An error will be reported. In the construction method, did you pass user in the new object (did you pass it in)?

    reply
    1
  • Cancelreply