<?php namespace app\index\controller; use app\index\model\User; class Index { protected $user; public function __construct(User $user) { $this->user = $user; } public function hello() { return 'Hello,' . $this->user->name . '!'; } }依赖注入