Welcome Guest, Not a member yet? Register   Sign In
"Main view"
#1

[eluser]donald.tbd[/eluser]
Hello,

Ive been working with php for some time now but i am new to CI and wanted to ask a little bit of guidance. Before CI i used my own framework and i like CI because it reminds me a little bit of my own.

In my own framework i had a static frame, that i called "main view". It looked a bit like this:

<html>
<head>
...
</head>
<body>
<div class="header">...</div>
<div class="menu">...</div>
<div class="menu">&lt;?=$content?&gt;</div>
<div class="footer">...</div>
&lt;body&gt;
&lt;/html&gt;

Now everything in this view is pretty much static except the $content part. $content was the dynamic part and it was basicly another "subview" passed down to this "main view". "Subview" could just be a table of dynamic content witohut anything else" The point of this "main view" was ofcorse not to write every static part again and again.
It could be used like this:

&lt;?php
$data = *selection from db or something like this*
$subview = $this->loadView('subview', $data);
$mainview = $this->loadView('mainview', $subview);
print $mainview;
?&gt;

Now ive been looking around but cant seem to find how can i accomplish something similar in CI.
I
would be thankful for any advice! Smile
#2

[eluser]cideveloper[/eluser]
This will work.

Check Returning views as data at the bottom.

controller

Code:
$db_results = "selection from db or something like this";
$data['content']= $this->load->view('subview', $db_results, true);
$this->load->view('mainview', $data);

view

Code:
&lt;html&gt;
  &lt;head&gt;
    ...
  &lt;/head&gt;
  &lt;body&gt;
  <div class=“header”>...</div>
  <div class=“menu”>...</div>
  <div class=“menu”>&lt;?=$content?&gt;</div>
  <div class=“footer”>...</div>
  &lt;body&gt;
&lt;/html&gt;
#3

[eluser]donald.tbd[/eluser]
Thank you Smile
#4

[eluser]donald.tbd[/eluser]
Just out of interest, is there a better way of keeping views seperate from everything static? How do you guys keep from typing the static stuff over and over again?
#5

[eluser]InsiteFX[/eluser]
MY_Controller

InsiteFX
#6

[eluser]donald.tbd[/eluser]
Thanks, was reading up on my_controller and found this in the wiki:
http://codeigniter.com/wiki/Header_and_F...ge_-_jedd/




Theme © iAndrew 2016 - Forum software by © MyBB