返回thinkph......登陆

thinkphp5.1中构造方法依赖注入

光棍叔2019-04-16 22:01:40333

//thinkphp5.1中构造方法依赖注入

class Index{
   protected $user;
   public function __construct(User $user)
   {
       $this->user = $user;
   }

   public function hello()
   {
       return 'Hello,' . $this->user->name ;
   }

}

最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送