Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Codeigniter : Two Step View - Concept Implementation

5.005 Aufrufe

Veröffentlicht am

Codeigniter two step view implementation

Veröffentlicht in: Technologie
  • Als Erste(r) kommentieren

Codeigniter : Two Step View - Concept Implementation

  1. 1. CodeIgniterTwo Step View Concept Implementation Abdul Malik Ikhsan http://slideshare.net/samsonasik
  2. 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. 3. Two Step View, a simple thought• Get View Content rendered• Then, `copy` the content into the html layout
  4. 4. Mention the ‘components’ needed• Hook ~> initialize• Helper ~> ‘generate’ two step view• Layout View ~> ‘echo-ing’ it
  5. 5. 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 */
  6. 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. 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. 8. 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 */
  9. 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. 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. 11. Show Time ;) With output buffering Without output buffering
  12. 12. Terima Kasih
  13. 13. 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

×