最近苏州网站建设在研究ThinkPHP5,利用构建方法快速渲染页面
class ldBulider extends Controller { public $element_path; /*组件路径*/ public $base_template='common/extend_base'; /*渲染模板*/ protected $out_html; /*合并页面内容*/ public function _initialize(){ $this->element_path=APP_PATH.'/common/lib/ldBuilder/view'; } /** 设置文档标题 * @param $title * @return $this * @auther wusn <message@jswusn.com> */ public function setMateTitle($title){ return $this->assign('mate_title',['title'=>$title]); } /** 设置面包屑 * @param array $array * @return $this * @auther wusn <message@jswusn.com> */ public function setPosition($array=[]){ return $this->assign('position',$array); } /** 模板赋值 * @param mixed $name * @param string $value * @return $this * @auther wusn <message@jswusn.com> */ public function assign($name, $value = ''){ $vars=parent::assign($name, $value); return $vars; } /** 渲染 * @param string $template * @param array $vars * @param array $replace * @param array $config * @return mixed * @auther wusn <message@jswusn.com> */ public function fetch($template = '', $vars = [], $replace = [], $config = []){ empty($template)?$template=$this->base_template:''; return parent::fetch($template, $vars, $replace, $config); } /** 只渲染不加载模板 * @param string $content * @param array $vars * @param array $replace * @param array $config * @return mixed * @auther wusn <message@jswusn.com> */ public function display($content = '', $vars = [], $replace = [], $config = []){ return parent::display($content , $vars, $replace, $config); } }
以上代码由(Ldcms)项目团队构思,苏州网站建设整理!