6视图过滤

视图过滤

可以对视图的渲染输出进行过滤

<?php
namespace app\index\controller;

use think\facade\View;

class Index 
{
    public function index()
    {
        // 使用视图输出过滤
        return View::filter(function($content){
        	return str_replace("\r\n",'<br/>',$content);
        })->fetch();
    }
}
复制

如果使用view助手函数进行模板渲染输出的话,可以使用下面的方式

<?php
namespace app\index\controller;

class Index 
{
    public function index()
    {
        // 使用视图输出过滤
        return view()->filter(function($content){
        	return str_replace("\r\n",'<br/>',$content);
        });
    }
}
复制
上一篇:6模板变量 下一篇:6模板渲染