Welcome Guest, Not a member yet? Register   Sign In
Have one view page for my application.
#1

[eluser]techguy101[/eluser]
Hi,

I'm extremely new to CI. I have skimmed through the User Guide and am getting to grips with things.

I have began converting one of my own apps to CI but would like to know:

Is it possiblw to have just one view and then a subview. for example: I would like to have oe view that shows the general application layout like header, footer, navbar etc. Then a sub view that shows maybe my search results and reports etc..

I currently have just one Controller and many functions. For each function it loads a view passing $data (like the blog video tutorial).

What to do??

Sorry for the scattered post..

Thanks..
#2

[eluser]jedd[/eluser]
Hi techguy101 and welcome to the CI forums.

[url="http://codeigniter.com/wiki/Header_and_footer_and_menu_on_every_page/"]Here's how I do it[/url]
#3

[eluser]bobbob[/eluser]
Yes you can.
Just load the header with the navbar in it and then load the footer at the end of your one view page.
The one view can just do whatever it does with the results.
Controller:
Code:
function some_page()
    {
            $data['title'] = 'Help';
                        ///put your navbar in the header file which is also in the views folder.
            $data['header'] = $this->load->view('header',$data);
                        $query = 'YOUR QUERY";
                        $data['query'] = $query;
            $this->load->view('home/oneview',$data);
    }

Your one view page has the foreach on the query followed by
$this->load->view('footer');

Hope this helps
#4

[eluser]techguy101[/eluser]
Wow, they were speedy replies..thanks guys.

I'm after going with bobbob's solution..it works like a treat.

One more thing. I just put an array at the very beginning of header.php to store menu items. I then use a for each loop to print them out in the nav bar furhter down..it will make adding menu items easy but is it the right way to do things??

Example:

Code:
<?php
    $navBar = array(
                        array('Home','home'),
                        array('Transactions','/transaction'),
                        array('Customers','/customer')
                        );
?>
<!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;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
    &lt;meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /&gt;
    &lt;style media="all" type="text/css"&gt;@import "http://192.168.72.128/grain/css/all.css";&lt;/style&gt;
    [removed][removed]



&lt;/head&gt;
&lt;body&gt;
<div id="main">
    <div id="header">
        <a href="splash.php" class="logo"><img src="img/logo.gif" width="101" height="29" alt="" /></a>
        <ul id="top-navigation">
            &lt;?php    
                    // Print out top navigation bar and apply active state to currently open page link.
                    foreach($navBar as $link):
                        if(strnatcasecmp($this->uri->segment(2),$link[0]) == 0)
                        {
                            echo '<li class="active"'; ?&gt;><span><span>&lt;?php echo $link[0];
                        }
                        else
                        {
                            echo '<li><span><span>'.anchor($link[1],$link[0]). '</span></span></li>';
                        }
                    endforeach;
            ?&gt;
        </ul>
    </div>


What do you think of this code? How would you improve it?

Thanks guys..

P.S. I only have <5 hours experience with CI but I absolutely love it!!




Theme © iAndrew 2016 - Forum software by © MyBB