首页 > 编程教程 > Yii2.0 视频教程
2015
10-22

Yii2.0视频第十一讲——入理解View——基本功能(Render)

Controller当中可使用的render方法


    //显示view和layout
    $this->render('about.php',['test'=>5]);

    //只显示view
    $content = $this->renderPartial('about',['test'=>5]);

    //只显示layout
    $this->renderContent($content);

    //显示指定的文件
    $this->renderFile('full file name',['test'=>5]);

    //只显示view(包含Head Body)
    $this->renderAjax('about',['test'=>'test']);


View当中可使用的render方法


    //只显示view
    $this->render('about.php',['test'=>5]);

    //显示指定的文件,和Controller里面的renderFile功能一样,其实它就是Controller里面的方法调用的这个方法
    $this->renderFile('full file name',['test'=>5])

    //显示指定的文件,和上面的区别,这个只能指定php文件,上面的可以指定其它模板引擎所使用的view文件
    $this->renderPhpFile('full file name',['test'=>5]);

    //和Controller里面的功能一样
    $this->renderAjax('about',['test'=>5])


查找view文件的4种方式

  • 别名开头,路径指定view文件
    @app/views/site/about.php
  • //开头,使用 app目录下面的views
    //site/about.php
  • /开头,使用当前Module中的views
    /site/about.php
  • 直接使用字符串
            a、在Controller里面,ViewContextInterface接口返回的view
            
            b、在View页面中,render指定的View要和在Controller调用的View一个目录

在线播放

下载地址

关注编程技巧 回复19领350本编程书籍

编程技巧