The Partial Library |
[eluser]micha8l[/eluser]
Partial Library will help you develop your application faster, no need for template engines here! Step one, copy and paste the library to application/libraries/Partial http://pastebin.com/wqNQBeE1 Step two, create a layout file. application/views/layout_three_column.php Code: <!DOCTYPE html> Step three, add some partial views. application/views/featured.php Code: <?php if(isset($featured_articles)): ?> application/views/popular.php Code: <?php if(isset($popular_articles)): ?> Step four, modify the library $uri property to match your default controller! application/libraries/Partial.php Code: $this->uri = ($uri)? $uri : 'home'; Step five, add your partial view paths to $this->views application/libraries/Partial.php Code: $this->views = array('featured', 'popular'); Step six (optional), create config.php - views will be loaded from config file application/config/partial.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Step seven, create a controller application/controllers/articles.php Code: <?php if( ! defined('BASEPATH')) exit('No direct script access allowed!'); Want a shorthand method? Code: $this->partial->replace(array('left' => 'featured_articles')); How about loading partials into multiple positions? Code: $this->partial->replace(array( Don't want your article to show when you're paginating comments? No problem! Code: if($pagination_offset > 0) What's that you say? User is not logged so you want to remove a partial? Code: if( ! $this->session->userdata('logged_in')) // or something to that extent I'm actively developing this class, I'll update regularly, I've got it working in production. I remove the "die()" statement as these are for development. When I get the time I'll intergrate it with CI's ENVIRONMENT constant. I'm thinking about implementing a role based access system for the $views property too. Suggestions welcome! |
Messages In This Thread |
The Partial Library - by El Forum - 03-08-2012, 11:49 PM
The Partial Library - by El Forum - 03-09-2012, 12:04 AM
The Partial Library - by El Forum - 03-09-2012, 12:26 AM
The Partial Library - by El Forum - 03-09-2012, 05:30 AM
The Partial Library - by El Forum - 03-09-2012, 12:34 PM
The Partial Library - by El Forum - 03-09-2012, 11:40 PM
The Partial Library - by El Forum - 08-09-2012, 07:06 PM
|