Codeigniter : Two Step View - Concept Implementation
Upcoming SlideShare
Loading in...5
×
 

Codeigniter : Two Step View - Concept Implementation

on

  • 3,466 views

Codeigniter two step view implementation

Codeigniter two step view implementation

Statistics

Views

Total Views
3,466
Views on SlideShare
3,457
Embed Views
9

Actions

Likes
1
Downloads
31
Comments
0

2 Embeds 9

http://localhost 5
http://www.slashdocs.com 4

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Codeigniter : Two Step View - Concept Implementation Codeigniter : Two Step View - Concept Implementation Presentation Transcript

    • CodeIgniterTwo Step View Concept Implementation Abdul Malik Ikhsan http://slideshare.net/samsonasik
    • Two Step View• Turns domain data into HTML in two steps: first by forming some kind of logical page, then rendering the logical page into HTML. ( Martin Fowler )
    • Two Step View, a simple thought• Get View Content rendered• Then, `copy` the content into the html layout
    • Mention the ‘components’ needed• Hook ~> initialize• Helper ~> ‘generate’ two step view• Layout View ~> ‘echo-ing’ it
    • Initializing ( 1 )<?phpclass Initializetwostepview{ public function __construct() { } public function initialize() { ob_start(); //Turn on output buffering }}/* End of file Initializetwostepview.php *//* Location: ./application/hooks/Initializetwostepview.php */
    • Initializing ( 2 )$hook[pre_controller][] = array(class => Initializetwostepview,function => initialize, filename => Initializetwostepview.php, filepath => hooks, // params => array() );/* End of file hooks.php *//* Location: ./application/config/hooks.php */
    • <?php ‘Generate’if ( ! function_exists(show)){ function show($view,$data) { //get content before view rendered $beforeshow = ob_get_clean(); // ~ Get current buffer contents //Assigning by reference allows you to use the original CodeIgniter object //rather than creating a copy of it. $this is for model,view,and controller only ;) $ci = & get_instance(); //combine into one string ;) $stringcontent = $beforeshow.$ci->load->view($view, $data, TRUE); //set datacontent ;) $datacontent[content] = $stringcontent; //load layout view ;) $ci->load->view(layout, $datacontent); }}/* End of file layout_helper.php *//* Location: ./application/helpers/layout_helper.php */
    • Testing<?phpclass Test extends CI_Controller{ public function __construct() { parent::__construct(); $this->load->helper(layout); } public function index() { $data = array(); $view = test_view; echo <b><font color="red">hello, im showed inside the view layout ;)</font></b> <br />; show($view,$data); }}/* End of file test.php *//* Location: ./application/controllers/test.php */
    • The content<p class=“article”> this is test view</p><?php/* End of file test_view.php *//* Location: ./application/view/test_view.php */
    • ‘Echo-ing’ in the Layout<html> <head> <title>CI with Layout</title> </head> <body> <h1> Header</h1> <div id="content"> <?php echo $content; ?> </div> <h1>Footer</h1> </body></html><?php/* End of file layout.php *//* Location: ./application/view/layout.php */
    • Show Time ;) With output buffering Without output buffering
    • Terima Kasih
    • This presentation contained copyrighted material licensed under variouscreative commons licenses unless otherwise noted:References• CodeIgniter User Guide• http://martinfowler.com/eaaCatalog/twoStepView.html• http://slideshare.net/samsonasik• http://samsonasik.wordpress.com