赣南脐橙

keybr

佰草伐

导航

thinkphp 依赖注入

<?php
namespace app\index\controller;

/* 
*URl访问
*/
class Demo1
{
    public function getName($name="peter")
    {
        return $name;
    }
    //依赖注入
    public function getMethod(\app\common\Temp $temp)
    {
        $temp->setName("wom");
        return $temp->getName();
    }
    public function bindClass()
    {
        \think\Container::set('temp','\app\common\Temp');
        $temp=\think\Container::get('temp',['name'=>'nishiwo']);
        return $temp->getName();
    }
    public function bindClosure()
    {
        \think\Container::set('demo',function($domain){
                return $domain;
        });
        return \think\Container::get('demo',['domain'=>'nishi']);
    }
}

  php知识网

posted on 2020-09-10 15:24  佰草伐  阅读(185)  评论(0编辑  收藏  举报

keybr

php基础知识

Wood Furniture