Welcome Guest, Not a member yet? Register   Sign In
automatically load layout
#1

[eluser]runrun[/eluser]
I got a layout like this, it's called layout_view.php

Code:
<html lang="en">
<head>
</head>
<body>
            <!--load my view here-->  
</body>
</html>

I got a view looks like this, it's called register_view.php

Code:
<h1>register</h1>
    &lt;form method="post" action=""&gt;
        &lt;input type="text" name="name" value="" /&gt;
    &lt;/form&gt;

when I do this
Code:
class Register extends controller{
    function index()
    {
       $this->load-view('register_view')
    }
}

I want the output will be like this

Code:
&lt;!--my register view will be inside my layout--&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
            <h1>register</h1>
            &lt;form method="post" action=""&gt;
                &lt;input type="text" name="name" value="" /&gt;
            &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

So, how would you do that ?
#2

[eluser]Eric Barnes[/eluser]
I always use a simple template library or extend the output for this. Here is a quick example:
http://ericlbarnes.com/blog/post/code-ig...e-tutorial
#3

[eluser]ranjudsokomora[/eluser]
Hello runrun,
You could do a number of things here... Here are a few:

# 1 You could send a view variable and load a secondary view inside layout_view.php
Your controller would look like:
Code:
class Register extends controller{
    function index()
    {
       $data['secondary_page'] = "register_view";
       $this->load-view('register_view',$data)
    }
}

And your view would look like:
Code:
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
            &lt;!--load my view here--&gt;  
            &lt;?PHP $this->load->view($secondary_page); ?&gt;
&lt;/body&gt;
&lt;/html&gt;


# 2 You could break up your layout_view.php into two views, and using your controller you could load three total views. So you would have something like this:

header_view.php
Code:
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;

register_view.php
Code:
<h1>register</h1>
    &lt;form method="post" action=""&gt;
        &lt;input type="text" name="name" value="" /&gt;
    &lt;/form&gt;

footer_view.php
Code:
&lt;/body&gt;
&lt;/html&gt;

Your controller would look like this:
Code:
class Register extends controller{
    function index()
    {
       $this->load->view('header_view');
       $this->load->view('register_view');
       $this->load->view('footer_view');
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB