Welcome Guest, Not a member yet? Register   Sign In
Creating a Layout Handler rather than using each Controler to render the full page.
#1

[eluser]Xeoncross[/eluser]
Well, I am loving the speed and design of the system so far. However, besides the session handling, the fact that there is no master-layout-system kind of gets me.

I am used to Models, Modules, Plugins (or whatever) being called by a main controller and then the output of that Module being returned to the main controller ($content). The main controller then calls a "layout.php" file and places the $content in it and gives the layout a chance to call other functions like get_recent_comments() and random_quote().

This is the way most CMS handle placing the $content of some Model/plugin into the set "site-wide" layout.

Now with Zend and CI I am introduced to the idea that the Controller could/should handle all this.

Code:
<?php

class Page extends Controller {

   function index()
   {
      $data['page_title'] = 'Your title';
      $data['content'] = 'My Page Text';
      $this->load->view('header');
      $this->load->view('menu');
      $this->load->view('content', $data);
      $this->load->view('footer');
   }

}
?>

I don't like the style of setting the layout sections/views within the controller because now my layout is tied to the Controller - i.e. my Controller is becoming a View!!!

What if I delete the "header" view from my design?
What if I add a new "recent_comments" view?

Not only that, but now I have to type all that code over again in EACH controller so that they all render the FULL page.

IMHO, this is just a bad idea. ;-)


So how could a "master layout" be built that received content from the controller but was free from that controller in every other way and allowed other controllers to add content to the layout?

You know, like a CMS that has a dynamic/changing Nav, Sidebar, and Header.


Messages In This Thread
Creating a Layout Handler rather than using each Controler to render the full page. - by El Forum - 07-17-2008, 05:12 PM



Theme © iAndrew 2016 - Forum software by © MyBB