zoukankan      html  css  js  c++  java
  • Thinkphp5.0 控制器向视图view赋值

    Thinkphp5.0 控制器向视图view的赋值


    方式一(使用fetch()方法的第二个参数赋值):

    <?php
    namespace appindexcontroller;
    use thinkController;
    
    class Index extends Controller
    {
        public function study_view(){
            
            return $this->fetch('study_view',[
                'id' => 1,
                'name' => 'li lei',
                'age' => 10
            ]);
        }
    }

    方法二(使用assign()方法赋值):

    <?php
    namespace appindexcontroller;
    use thinkController;
    
    class Index extends Controller
    {
    
        public function study_view(){
            $this->assign('id',1);
            $this->assign('name','li lei');
            $this->assign('age','12');
            return $this->fetch();
        }
    }

    方法三(使用thinkController类的view对象赋值):

    <?php
    namespace appindexcontroller;
    use thinkController;
    
    class Index extends Controller
    {
    
        public function study_view(){
            $this->view->id = 2;
            $this->view->name = 'li lei';
            $this->view->age = 15;
            return $this->fetch();
        }
    }

    方法四(使用View类的静态方法赋值):

    <?php
    namespace appindexcontroller;
    use thinkController;
    use thinkView;
    
    class Index extends Controller
    {
    
        public function study_view(){
            View::share('id',6);
            View::share('name','zhang san');
            View::share('age',20);
            return $this->fetch();
        }
    }

  • 相关阅读:
    冲刺阶段 day1
    目标系统流程图 数据流图
    团队作业二
    校外实习报告(十二)
    校外实习报告(十一)
    第二周实习总结
    校外实习报告(十)
    校外实习报告(九)
    校外实习报告(八)
    校外实习报告(七)
  • 原文地址:https://www.cnblogs.com/gyfluck/p/9408437.html
Copyright © 2011-2022 走看看