Best practices -> where to put template arrays |
[eluser]eveiga[/eluser]
Hi there, Right now i'm using calendaring class and table helper in a simple site i'm developing. My question is, regarding developing best practices, where would I put the templates that I have created to the styling of both? At the moment, i'm using the controllers constructor because I use both templates in 90% of the functions! Best regards, Edgar
[eluser]bretticus[/eluser]
I would assume to follow CI convention, you're store them in either the config.php file or your own and autoload it. Details: http://ellislab.com/codeigniter/user-gui...onfig.html
[eluser]JayTee[/eluser]
I just noticed something today (probably not "news" to everyone - but it's news to me) If you put a file in your application/config folder with the SAME NAME as your library, CI will load that config file auto-magically All you gotta do for loading your template (for the calendar) is put it into application/config/calendar.php I'll use the example [url="http://ellislab.com/codeigniter/user-guide/libraries/calendar.html"]from the documentation[/url] and make it so that it will work with this technique: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); You can even set your other preferences such as local_time, start_day, etc (see the documentation) and they will get set at load time. The "magic" happens in CI's Loader.php file (take a look around line 860). Without going over the code, here's what happens: When you call the "load" method Code: $this->load->library('libname') You can use the calendar's initialize method to pass an additional config array if needed - it won't over-write your existing settings. Pretty kewl :coolsmile:
[eluser]JayTee[/eluser]
Just for fun and games - I decided to extend the Calendar class (just a little bit) to make it a little "cleaner" than the big-long-string that the documentation suggests. application/config/calendar.php: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Replace the Calendar Libraries "parse_template" method: (application/libraries/MY_Calendar.php): Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); voila - you can now use the array-based template instead of the other one. -- Edit: If you wanted to just over-ride individual template items - you could change the MY_Calendar class so that it iterates over your template array and only replaces the keys in the $this->temp variable that the Calendar class uses... just a thought. |
Welcome Guest, Not a member yet? Register Sign In |