Welcome Guest, Not a member yet? Register   Sign In
Loading dynamic content into blockviews
#1

[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,
Svante
#2

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

Code:
$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.
Code:
$this->load->view('layout',$page);
In this 'layout' view, you can do the following at the appropriate place:
Code:
<?php
if (isset($header)) echo $header;
if (isset($adblock)) echo $adblock;
if (isset($sidebar)) echo $sidebar;
?>
#3

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

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

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


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


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


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

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

&lt;/body&gt;&lt;/html>
&nbsp;
&nbsp;
&nbsp;
#4

[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!

Code:
<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>
            <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>
        </div>
    </div>
</div>
<div class="wrapper">
<div class="side-shadow-l png">
    <div class="side-shadow-r png">
#5

[eluser]InsiteFX[/eluser]
Code:
$page['header'] = $this->load->view('header');
$page['adblock'] = $this->load->view('adblock');
$page['sidebar'] = $this->load->view('sidebar');  

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

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB