CodeIgniter Forums
Load Views Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Load Views Problem (/showthread.php?tid=14812)



Load Views Problem - El Forum - 01-16-2009

[eluser]breastfed[/eluser]
Hello

i am new to CI. I read Tutorials, did the Video Tutorial and read Board Threads but i can't figure out the Following:

I have a main Website Structure like this:

Code:
<html>
  <head>
    <title>domain.com - Title ##PageTitle##</title>
  </head>

  <body>

    <div id="menu">
      &lt;!-- Menu on each Page --&gt;
    </div>

    <div id="main">
      &lt;!-- Include the Content from each URL (e.g. /about, /blog, /contact, ...) --&gt;
    </div>

    <div id="footer">
      &lt;!-- Footer on each Page --&gt;
    </div>

  &lt;/body&gt;
&lt;/html&gt;

As you can see, i want to have a Basemenu-File and a Footer-File wich is included in each Page.

Now i want to load the Content of every Page instead of including whole Pages beginning with &lt;html&gt;.
Only Content wich is relevant to the URL.

I know that the views are the files which provides the Content and the Views are fed by the Controllers, but i can figure out how to solve my Problem.

Please help me out :/


Load Views Problem - El Forum - 01-16-2009

[eluser]ecigraeme[/eluser]
In this example Home is the default controller. The web site would have two pages /Home/index and /Home/about. The header view could contain all the html headers then the other views could hold fragments of the html. Im quite new to code ignite so i could have it all wrong, but hopefully this will help you.

class Home extends Controller
{
function index()
{
$data['pageTitle'] = "My web site homepage";

$this->load->view('header',$data);
$this->load->view('menu');
$this->load->view('homepage.php',$data);
$this->load->view('footer',$data);
}

function about()
{
$data['pageTitle'] = "About me";

$this->load->view('header',$data);
$this->load->view('menu');
$this->load->view('thaboutpage.php',$data);
$this->load->view('footer',$data);
}
}

Graeme


Load Views Problem - El Forum - 01-16-2009

[eluser]breastfed[/eluser]
But is there a main Template wich includes the Content or is it Copy and Paste for all WEbsites?


Load Views Problem - El Forum - 01-16-2009

[eluser]meigwilym[/eluser]
I'm afraid your question isn't very clear.

Are you using a database, or will your content be static pages?

The above example should help you along [although $this->load->view(‘thaboutpage.php’,$data); should be $this->load->view(‘thaboutpage’,$data);]. Can I suggest you splitting your template into a header.php and footer.php, and writing the content pages as needed. You can then load them as in the example.

Mei