Welcome Guest, Not a member yet? Register   Sign In
file view reuse without reload
#1

[eluser]andrey55555[/eluser]
Hi!
I make output goods for shop so: catalog output used file view “catalog”, wherein calling file view “goods” for each goods.
So for output 100 goods: loading one file view “catalog” and loading 100 file view “goods”.

How right organize reused file view “goods” without loading 100 times file view “goods” ?

Thanks.
#2

[eluser]ivantcholakov[/eluser]
One way is to use some kind of parser. CodeIgniter has a simple one built-in. This is the idea, let us suppose we are within the view:

Code:
<?php defined('BASEPATH') || exit('No direct script access allowed');

$ci = get_instance();

$ci->load->library('parser');

$goods_template = @ file_get_contents(dirname(__FILE__).'/some_path/goods_template.php');

?>

html...

<?php

foreach ($goods as $good) {
    echo $ci->parser->parse_string($goods_template, $good, FALSE);
}

?>

html...

#3

[eluser]andrey55555[/eluser]
Thanks. It's nice idea.
#4

[eluser]ivantcholakov[/eluser]
Actually, for such cases I prefer to use the Mustache parser. It has PHP and JavaScript implementations, so I can render a given template on the server side or on the browser side at will. But if you don't want to introduce yet another technology within your project - try with the CodeIgniter's parser.




Theme © iAndrew 2016 - Forum software by © MyBB