Loading dynamic content into blockviews

[eluser]Svante Hansson[/eluser]
I'm in the process of converting a old sluggish website to using the CI framework. I've currently stripped down the frontpage into 8 views (header, previous article, highlight, adblock and so on) so I can just include them whenever I want to use them (depending on page). I'm trying to figure out the best way of populating those views without having to clutter up the controller with 4~ new modules everytime I load a page. I would like some way of loading the view with some sort of default data that's loaded from the database.

Any ideas?

Kind regards,

Have you thought about using the third parameter of the $this->load->view to load each block into a variable?

$page['header'] = $this->load->view('header',$data,true);
$page['adblock'] = $this->load->view('adblock',$data,true);
$page['sidebar'] = $this->load->view('sidebar',$data,true);

You can load $data with any information from the DB that you want that view to display.

Then you need an overall view that pulls it all together and displays it.
In this 'layout' view, you can do the following at the appropriate place:
if (isset($header)) echo $header;
if (isset($adblock)) echo $adblock;
if (isset($sidebar)) echo $sidebar;

In addition to the above I would add the HTML layout Divs and endeavour to not have any HTML script in the "Partial Views":

<!doctype html>
  &lt;title&gt;&lt;?php echo $title;?&gt;&lt;/title&gt;
  &lt;?php echo $header;?&gt;
<div id='container'>

   &lt;?php if ( ONLINE && isset($adblock))  { ?&gt;
     <div id='adblock'>
       &lt;?php echo $adblock;?&gt;
   &lt;?php } ?&gt;

  &lt;?php if (isset($sidebar)) { ?&gt;
    <div id='sidebar'>
      &lt;?php echo $sidebar;?&gt;
  &lt;?php } ?&gt;

  <div id='dynamic_content'>
     &lt;?php echo $dynamic_content;?&gt;

</div>&lt;?php /* container */ ?&gt;

<div id='footer'>
  &lt;?php  echo $footer;><


[eluser]Svante Hansson[/eluser]
An excerpt of the page just do see how bloody much divs to keep track :p Sometimes it's not even impossible not splitting up parts of the same div. It's so nested.

Thanks for the replies so far!

<div id="page-bg">
    &lt;!--Begin Top Header Bar--&gt;
    <div id="top-bar" class="png">
        <div class="wrapper">
            <div class="links-block">

                &lt;!-- Meny --&gt;
                <ul class="menu">
                    &lt;!-- generated menu here --&gt;
            <div id="accessibility"><div id="buttons"></div></div>
            <div class="date-block">
                <span class="date1"></span>
                <span class="date2"></span>
                <span class="date3"></span>
<div class="wrapper">
<div class="side-shadow-l png">
    <div class="side-shadow-r png">

$page['header'] = $this->load->view('header');
$page['adblock'] = $this->load->view('adblock');
$page['sidebar'] = $this->load->view('sidebar');  

$this->load->view('template');    // or layout!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.