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();
        }
    }

  • 相关阅读:
    在eclipse中运行正常的java项目放到tomcat中报错的解决办法
    xml和json之间的转换
    读取文件工具类
    java解压文件
    常用语句
    形容词&&人称词
    称呼
    单词-数字使用
    单词-数字:十位20-29
    单词-数字:十位11-19
  • 原文地址:https://www.cnblogs.com/gyfluck/p/9408437.html
Copyright © 2011-2022 走看看