What is the difference between view and render?

半腔热情 提交于 2021-02-07 10:28:47

问题


What is the difference between view and render in codeigniter?


回答1:


some template libraries use $this->template->render(); to output the rendered content based on your template. (you must have the template library installed obviously)

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

is in effect the same as

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

template libraries save the need to load each partial view every time.




回答2:


Render is not an out-of-the-box Codeigniter function for loading view files. Render is primarily used by Codeigniter template libraries like Collin William's Template Library or Phil Sturgeon's Template Library.

The following two methods for view files are supported by Codeigniter right in the core code without using third party libraries or core extensions.

$this->load->view()

The standard and most used way of loading a view file. Does not support any fancy syntax except alternative control syntax structured PHP code or standard PHP code.

$this->parser->parse()

Using the in-built Codeigniter parser which supports a Smarty like syntax only not as powerful. Also allows you to code view files using standard PHP and HTML as well.



来源:https://stackoverflow.com/questions/4758978/what-is-the-difference-between-view-and-render

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!