SlideShare a Scribd company logo
1 of 13
Download to read offline
CodeIgniter
Two 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 )
<?php

class 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
<?php

class 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, i'm 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 various
creative commons licenses unless otherwise noted:


References
•   CodeIgniter User Guide
•   http://martinfowler.com/eaaCatalog/twoStepView.html
•   http://slideshare.net/samsonasik
•   http://samsonasik.wordpress.com

More Related Content

What's hot

Dance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkDance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech Talk
Michael Peacock
 
Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation
Compare Infobase Limited
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
Michael Peacock
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
Jeremy Kendall
 

What's hot (20)

What happens in laravel 4 bootstraping
What happens in laravel 4 bootstrapingWhat happens in laravel 4 bootstraping
What happens in laravel 4 bootstraping
 
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
 Connecting Content Silos: One CMS, Many Sites With The WordPress REST API Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
 
Dance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkDance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech Talk
 
Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation
 
Add loop shortcode
Add loop shortcodeAdd loop shortcode
Add loop shortcode
 
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
 
XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
CodeIgniter 3.0
CodeIgniter 3.0CodeIgniter 3.0
CodeIgniter 3.0
 
ACL in CodeIgniter
ACL in CodeIgniterACL in CodeIgniter
ACL in CodeIgniter
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress Developers
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Working with WP_Query in WordPress
Working with WP_Query in WordPressWorking with WP_Query in WordPress
Working with WP_Query in WordPress
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Getting Started-with-Laravel
Getting Started-with-LaravelGetting Started-with-Laravel
Getting Started-with-Laravel
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro framework
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
 

Viewers also liked

2014 database - course 3 - PHP and MySQL
2014 database - course 3 - PHP and MySQL2014 database - course 3 - PHP and MySQL
2014 database - course 3 - PHP and MySQL
Hung-yu Lin
 

Viewers also liked (15)

WordPress and Zend Framework Integration with Vulnero
WordPress and Zend Framework Integration with VulneroWordPress and Zend Framework Integration with Vulnero
WordPress and Zend Framework Integration with Vulnero
 
Momchil Kyurkchiev Presentation
Momchil Kyurkchiev PresentationMomchil Kyurkchiev Presentation
Momchil Kyurkchiev Presentation
 
DB design
DB designDB design
DB design
 
2014 database - course 3 - PHP and MySQL
2014 database - course 3 - PHP and MySQL2014 database - course 3 - PHP and MySQL
2014 database - course 3 - PHP and MySQL
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
CodeIgniter - PHP MVC Framework by silicongulf.com
CodeIgniter - PHP MVC Framework by silicongulf.comCodeIgniter - PHP MVC Framework by silicongulf.com
CodeIgniter - PHP MVC Framework by silicongulf.com
 
Codeigniter : the security and the magic of hook
Codeigniter : the security and the magic of hookCodeigniter : the security and the magic of hook
Codeigniter : the security and the magic of hook
 
Week 3 database design
Week 3   database designWeek 3   database design
Week 3 database design
 
Modular PHP Development using CodeIgniter Bonfire
Modular PHP Development using CodeIgniter BonfireModular PHP Development using CodeIgniter Bonfire
Modular PHP Development using CodeIgniter Bonfire
 
Zend Framework 2 : Dependency Injection
Zend Framework 2 : Dependency InjectionZend Framework 2 : Dependency Injection
Zend Framework 2 : Dependency Injection
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Database design process
Database design processDatabase design process
Database design process
 
PHP Project PPT
PHP Project PPTPHP Project PPT
PHP Project PPT
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 

Similar to Codeigniter : Two Step View - Concept Implementation

TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
Alessandro Molina
 
BlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorksBlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorks
mwbrooks
 
Frameworks da nova Era PHP FuelPHP
Frameworks da nova Era PHP FuelPHPFrameworks da nova Era PHP FuelPHP
Frameworks da nova Era PHP FuelPHP
Dan Jesus
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
Yehuda Katz
 

Similar to Codeigniter : Two Step View - Concept Implementation (20)

Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
 
Code Igniter 2
Code Igniter 2Code Igniter 2
Code Igniter 2
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Codegnitorppt
CodegnitorpptCodegnitorppt
Codegnitorppt
 
Desbravando Web Components
Desbravando Web ComponentsDesbravando Web Components
Desbravando Web Components
 
Angular JS2 Training Session #2
Angular JS2 Training Session #2Angular JS2 Training Session #2
Angular JS2 Training Session #2
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
 
BlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorksBlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorks
 
Frameworks da nova Era PHP FuelPHP
Frameworks da nova Era PHP FuelPHPFrameworks da nova Era PHP FuelPHP
Frameworks da nova Era PHP FuelPHP
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Yii Introduction
Yii IntroductionYii Introduction
Yii Introduction
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
Getting to The Loop - London Wordpress Meetup July 28th
Getting to The Loop - London Wordpress Meetup  July 28thGetting to The Loop - London Wordpress Meetup  July 28th
Getting to The Loop - London Wordpress Meetup July 28th
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with example
 
实战Ecos
实战Ecos实战Ecos
实战Ecos
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Codeigniter : Two Step View - Concept Implementation

  • 1. CodeIgniter Two Step View Concept Implementation Abdul Malik Ikhsan http://slideshare.net/samsonasik
  • 2. 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 )
  • 3. Two Step View, a simple thought • Get View Content rendered • Then, `copy` the content into the html layout
  • 4. Mention the ‘components’ needed • Hook ~> initialize • Helper ~> ‘generate’ two step view • Layout View ~> ‘echo-ing’ it
  • 5. Initializing ( 1 ) <?php class Initializetwostepview { public function __construct() { } public function initialize() { ob_start(); //Turn on output buffering } } /* End of file Initializetwostepview.php */ /* Location: ./application/hooks/Initializetwostepview.php */
  • 6. 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 */
  • 7. <?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 */
  • 8. Testing <?php class 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, i'm showed inside the view layout ;)</font></b> <br />'; show($view,$data); } } /* End of file test.php */ /* Location: ./application/controllers/test.php */
  • 9. The content <p class=“article”> this is test view</p> <?php /* End of file test_view.php */ /* Location: ./application/view/test_view.php */
  • 10. ‘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 */
  • 11. Show Time ;) With output buffering Without output buffering
  • 13. This presentation contained copyrighted material licensed under various creative commons licenses unless otherwise noted: References • CodeIgniter User Guide • http://martinfowler.com/eaaCatalog/twoStepView.html • http://slideshare.net/samsonasik • http://samsonasik.wordpress.com