我有一个基本控制器,它在其构建器中注入一个User模型:
class BaseController extends Controller {
public $user;
public function __construct(User $user) {
$this->user = $user;
View::share('user', $this->user);
}
AuthController扩展了BaseController
class AuthController extends BaseController {
public function __construct(LDAP $ldap, User $user) {
parent::__construct($user);
$this->ldap = $ldap;
$this->user->setUsername('Username'); //This is not being called
}
如何从父控制器访问注入的模型并在其上调用方法?
如果我使用$ this-> user-> setUsername(' Username');从BaseController中正确调用该方法,但不是从子控制器调用。