Welcome Guest, Not a member yet? Register   Sign In
multiple view in one page....
#1

[eluser]henry178[/eluser]
Hi, this my first project whit CI.

in my principal controller I have this code:

Code:
class Prova extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
    }

    function index()
    {
        $this->load->view('template1/prova/head');
                $this->load->view('template1/prova/menu');
        $this->load->view('template1/prova/content');
        $this->load->view('template1/prova/footer');
    }
    
}

I don't understand how to set the view:

view head:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;title&lt;/title&gt;
&lt;/head&gt;
view menu:
Code:
<ul>
<li>one</one>
<li>two</one>
<li>three</one>
</ul>
view content:
Code:
&lt;body&gt;
<h1>content</h1>
&lt;/body&gt;
view footer:
[code ]
<div>footer</div>
&lt;/html&gt;
[/code ]

This impostation is correct? There 'a better way
Thanks
#2

[eluser]toopay[/eluser]
Please, use code tags when you posting your code
Code:
// Remove any space
[code ]&lt;!--YourCodeHere--&gt;[/code ]
It does, help anyone to read your code better.
#3

[eluser]henry178[/eluser]
[quote author="toopay" date="1304202062"]Please, use code tags when you posting your code
Code:
// Remove any space
[code ]&lt;!--YourCodeHere--&gt;[/code ]
It does, help anyone to read your code better.[/quote]

Perfect! Smile
#4

[eluser]toopay[/eluser]
Since some part of your view file (ussually) is always called in any controller (header and footer), then it will be more efficient, if you have some 'base' view file. Lets say you name it 'template.php', and you fill with something like this
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;&lt;?php echo $title ?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php $this->load->view('header') ?&gt;
&lt;?php $this->load->view($content) ?&gt;
&lt;?php $this->load->view('footer') ?&gt;
&lt;/body&gt;
&lt;/html&gt;

With above 'template', now you could easily pass a param from your controller like...
Code:
class Prova extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
    }

    function index()
    {
        $data = array(
                     // Specify the page Title
                     'title'    => 'This is My Title',
                     // Specify the view file name for content
                     'content'  => 'template1/prova/content',
                );
        $this->load->view('template',$data);
    }
    
}
#5

[eluser]henry178[/eluser]
thank you Toopay!

Very nice :-)
#6

[eluser]InsiteFX[/eluser]
You can also do it like this:
Code:
function index()
{
    $data = array(
        // Specify the page Title
        'title'    => 'This is My Title',
        // Specify the view file name for content
        'content'  => 'template1/prova/content',
    );

    $this->load->vars($data);
    $this->load->view('template');
}

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB