第一,原始方法
use think\Model; 使用use
$user=news User()
缺点,使用一个都要引入在实例化
第二,依赖注入
也要引入use
use think\Request;
public function test1(Request $request){
var_dump($request->param('name'));
}
第三,容器管理,管理这些依赖注入
1,bind('one','app\index\model\One');
return app('one')->name1;
2,简写 return app('app\index\model\One')->name1;
3,多个类绑定
bind([
'one' =>'app\index\model\One',
'user' =>'app\index\model\User',
]);
return app('user')->name;
4,provider.php 文件管理
return [
'one' =>'app\index\model\One',
'user' =>'app\index\model\User',
];
控制器直接调用 return app('one')->name1;
5,助手函数
request()->param('name')
6,门面模式
建facade文件夹
class App extends Facade
{
/**
* 获取当前Facade对应类名(或者已经绑定的容器对象标识)
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return 'app';
}
}
文章来自 www.96net.com.cn
标签:index,use,tp5.1,return,app,几种,实例,user,model From: https://www.cnblogs.com/96net/p/17115084.html