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

#11
[eluser]Al James[/eluser]
@sophistry

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

Instead of:

Code:
$this->sparks->store()->display();

You would use:

Code:
$this->sparks->store();
$this->sparks->display();

Longer but it should work!

#12
[eluser]sophistry[/eluser]
Thanks Al! That was easy. :-)

#13
[eluser]jbowman[/eluser]
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?

#14
[eluser]Al James[/eluser]
@jbowman

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!

#15
[eluser]jbowman[/eluser]
perfectly fine, this is spare time stuff for all of us, so the rapid response is appreciated Smile

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

Changes:

* 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.

Code:
<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:

Code:
//Instead of:

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

//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?

#17
[eluser]jbowman[/eluser]
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.

#18
[eluser]Al James[/eluser]
@jbowman

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:

Code:
$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?

#19
[eluser]jbowman[/eluser]
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

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

#20
[eluser]abmcr[/eluser]
Uaooooohhhh! very great work.... thank you... ciao


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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