Welcome Guest, Not a member yet? Register   Sign In
One structure and more contents..
#1

[eluser]ariok[/eluser]
Hi all! i'm really new with codeIgniter.. and i'd like to understand if CI is what i'm looking for..

i have a little question about how to struct a page when i need to repeat a structure and i have to change contents only.

Example:
i need two pages , "HOME" and "NEWS".
In this pages my footer, header and navigation bar are the same but in HOME i have contents for HOME and in NEWS contents for NEWS.

now... how to struct a situation like this in CI ??

Do i need to create different views for all Pages(news and home), with only few differences in contents??in this case... i have to repeat footer menu and header in all of my views!!??? uhm...

Thank you

Big Grin
#2

[eluser]ariok[/eluser]
i find this solution..

Two controllers, home.php and news.php which share a view
I.E.
Code:
//home.php---------------------
class Home extends Controller {
    function index(){    
        $this->load->view("general_view");
    }
        function printContent() {
         echo "<p>Some code...for home</p>";
        }
}

//news.php---------------------
class News extends Controller {
    function index(){    
        $this->load->view("general_view");
    }
        function printContent() {
         echo "<p>Some code...for news</p>";
        }

}

//general_view.php
&lt;html&gt;
.
.
<div id="content">
   &lt;?=$this->printContent()?&gt;
</div>
.
.
&lt;/html&gt;


but i'm not sure this is the better solution..Tongue

What do you think about that?
#3

[eluser]ariok[/eluser]
looking around i find this code...do you think this could be interesting for my problemS?

Code:
function _load_views()
    {
        $this->data['subheader'] = $this->load->view('examples_subheader', $this->data, true);
        $this->data['sidebar'] = $this->load->view('examples_sidebar', $this->data, true);
        $this->data['body_content'] = $this->load->view('dropdownlist_tpl', $this->data, true);
    }
#4

[eluser]ariok[/eluser]
http://codeigniter.com/wiki/Displaying_Multiple_Views/
here the solution... ehm...thank you...Big Grin
#5

[eluser]Cappinator[/eluser]
Hi Ariok,

That's what I use too. I put all that stuff into a library. Here's the code in case you're interested:

libraries/Template.php:
Code:
&lt;?php
if(!defined('BASEPATH')) exit('No direct script access allowed!');

class Template
{

  function Template()
  {
    $this->template =& get_instance();
  }

  function load_page($page, $data)
  {
    /* I put some code here that queries the db
       for a menu and other dynamic header/footer data */
    $to_load = $this->template->load->view('template/header', $data, true);
    $to_load .= $this->template->load->view($page, $data, true);
    $to_load .= $this->template->load->view('template/footer', $data, true);
    echo $to_load;
  }

  /* this class also contains other functions to query the db
     for stuff that goes into the header/footer views */

}
?&gt;

For a page such as your Home page, you could use this:
controllers/home.php
Code:
&lt;?php
class Home extends Controller
{
  function Home()
  {
    parent::Controller();
    $this->load->library('template');
  }

  function index()
  {
    $data = array('page_title' => 'My home page',
                  'page_footer' => 'Check out my news page!');
                  /* etc... put anything you plan on using in the header,
                     footer and your content page here like this.
                     Just put the dynamic stuff here.  Things that always
                     stay the same in your header and footer (such as copyright
                     for example, go straight into the header and footer views */
    $this->template->load_page('home_view', $data);
  }
}
?&gt;

views/template/header.php
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;?=$page_title?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

views/template/footer.php:
Code:
&lt;?=$page_footer?&gt;<br />
Copyright by me!
&lt;/body&gt;
&lt;/html&gt;

And your home.php file would contain just the contents of that page. Same goes for your news page.




Theme © iAndrew 2016 - Forum software by © MyBB