• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sparks : Caching Template system

[eluser]Al James[/eluser]

You can make it work in php4 by making one call per method:

Instead of:


You would use:


Longer but it should work!

Thanks Al! That was easy. :-)

Another thing I just discovered. You can't use $this for loading helpers and doing validation checks, however, $CI works as you're setting it using get_instance()

Is there any way to get $this working inside the templates again?

[eluser]Al James[/eluser]

Yes, thats a problem at the moment. I will fix it in the next version, or at the very least upload a new fix for this tonight (GMT time). Hope thats ok!

perfectly fine, this is spare time stuff for all of us, so the rapid response is appreciated Smile

[eluser]Al James[/eluser]
Sparks 1.1 is now available here: Sparks.v1.1.zip.


* Fixed used of $this inside view files. ($CI still works as well).
* Integrated into CI Loader class better.
* New feature You can now pass data arrays into the sparks_include function via an optional second argument. I.e.

<h2>Recent news</h2>

&lt;? sparks_include('newslist.php', array('news' => $recent_news)); ?&gt;

<h2>Popular news</h2>

&lt;? sparks_include('newslist.php', array('news' => $popular_news)); ?&gt;

This allows you to reuse 'parts' over and over again with separate data. Note that the supplied data are merged into the global variables, i.e. all the global variables are available in the sub-part, but also the variables you pass in!

* For PHP 4 users:

//Instead of:


//Can be replaced by:

$this->sparks->initialize($id, $group, $ttl);

//Less typing for php4 users!

Ok, it should be a drop in replacement. I have not had time to test this extensively. Please let me know if you find a problem.

I am planning v2.0 which will be quite different (internally)... Any suggestions?

Looks good, I put my loop for creating the language variable back into my copy. For now I just have it in the display function. I figure, I shouldn't be caching those anyway, good way to remind me and keep my synatax right.

[eluser]Al James[/eluser]

I will probably include your language stuff in version 2... Sorry I forgot last night for 1.1!

Theres two ways to think of it. One is the languages should not be cached (your approach), the other is to cache separate files depending on the language. But thats a silly idea (could lead to cache discrepancies between the languages). I cant see the overhead for dynamically including languages being that large...

Thanks for your suggestion!

Instead of looping over all the keys in the language I think it may be more efficient to do this:

$lang = $this->CI->lang->language;

Should work the same I think!

Also, does the language import bit need to be in the store() method as they are never cached?

I'm still not doing it in the store, though I haven't gone multi-lingual with my site either yet. Someone would want to do testing with a site that has at least two languages running to test failure modes.

And wow.. I really should have printed out that CI object, you're right, I was wasting time with that loop. One tweak, I'd pass it as a reference

$lang =& $this->CI->lang->language;

Uaooooohhhh! very great work.... thank you... ciao

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.