view和render有什么区别?

sha*_*vel 1 codeigniter

codeigniter中的视图和渲染有什么区别?

Ros*_*oss 5

一些模板库用于$this->template->render();根据您的模板输出呈现的内容.(你必须明确安装模板库)

function index()
{
    $this->template->set_template('main_template');
    $data['content'] = 'hello this is my content';
    $this->template->write_view('content', $data);    
    $this->template->render();
}
Run Code Online (Sandbox Code Playgroud)

实际上是一样的

function index()
{
    $data['content'] = 'hello this is my content';
    $this->load->view('template/header');
    $this->load->view('template/content', $data);
    $this->load->view('template/footer');
}
Run Code Online (Sandbox Code Playgroud)

模板库节省了每次加载每个局部视图的需要.