What's the difference between these two calls? What's the general difference between parse and view? When do I use parser->parse and when load->view?
$this->load->view('content', $data);
$this->parser->parse('content', $data, FALSE);
If I have this array:
$data = array(
'title' => 'Home Page',
'heading' => 'Heading'
);
$this->parser->parse('content', $data, FALSE);
In content.php view I can do both by calling parse function
echo $title;
echo '<h1>{heading}</h1>';
what's the difference?
As I understand The 3rd paramether of parse function can be TRUE or FALSE, when it's TRUE I can get values from the view like this
$string = $this->parser->parse('content',$data, TRUE);
how can I do that, what's the code in content?
load->view() does exactly what it says, it loads a view page.
parser->parse parses the page and can be used with views that contain template variables in place of PHP variables.
In application, both functions accomplish the objective of loading a view that contains HTML and PHP variables or template placeholders. However, parse is going to have more overhead, as it is not a native PHP solution, and is parsed to replace the templating values.
Consult the doumentation for more information:
http://ellislab.com/codeigniter/user-guide/general/views.html
http://ellislab.com/codeigniter/user-guide/libraries/parser.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With