Welcome Guest, Not a member yet? Register   Sign In
New user and view question
#1

[eluser]Unknown[/eluser]
Hello everyone! I'm brand new to codeigniter but I'm glad to see such an active community. Thank you for the great framework, this will make my getting back into coding much easier. Started in the mid 90's with PHP and then joined the military in 2003 haven't programmed since and wow have things changed! haha. Anyways.

I'm curious what the standard is for loading multiple views withing a controller, say I want to load the header of a page, then data formatted listings, then a footer template. How do people normally go about that. I'd imagine loading a view kinda terminates a controller. Thanks again.
#2

[eluser]Victor Michnowicz[/eluser]
I'm a fan of Phil Sturgeon's template library: http://getsparks.org/packages/template/show
#3

[eluser]wh1tel1te[/eluser]
I personally load the views as variables in my main template. Here's an extremely rough version of what I do:

Controller code:
Code:
<?php
function index()
{
    $html = array();
    $data = array();
    
    // Set my data vars here
    
    $html['header'] = $this->load->view('header', $data, TRUE);
    $html['body'] = $this->load->view('body', $data, TRUE);
    $html['footer'] = $this->load->view('footer', $data, TRUE);
    
    $this->load->view('template', $html);
}
?>

View code (template.php):
Code:
<header><?php echo $header; ?></header>
<div id="content">&lt;?php echo $body; ?&gt;</div>
<footer>&lt;?php $footer; ?&gt;</footer>
#4

[eluser]R_Nelson[/eluser]
I ran into this problem myself when i started with CI what i did was built a template and used
Code:
$this->load->view(name_of_view,$data_array)
it would look something like this
Code:
$this->load->view(includes/template,$data)
then in my template i use what i stored in $data to load my main view in the main area you can use $this->load->view() as many times as you want within the template!

heres an example of the controller
Code:
function about ()
    {
        $data['title'] = 'About Page';    
        $data['discription'] = '';
        $data['keyword'] = '';
        $data['main_content'] = 'site/about';
        $data['robot'] = 'all';
        $this->load->view('includes/template', $data);    
    }
and here is the template
Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;link rel="stylesheet" href="&lt;?php echo base_url();?&gt;css/main.css" type="text/css" media="screen" /&gt;
      &lt;link rel="shortcut icon" href="&lt;?php echo base_url();?&gt;images/favicon.png" /&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
    &lt;meta name="description" content="&lt;?php echo $discription; ?&gt;" /&gt;
    &lt;meta name="keywords" content="&lt;?php echo $keyword; ?&gt;" /&gt;
    &lt;meta name="revisit-after" content="7 days" /&gt;
    &lt;meta name="ROBOTS" content="&lt;?= $robot ?&gt;" /&gt;
    &lt;title&gt;Northwood Web Design - &lt;?php echo $title; ?&gt;&lt;/title&gt;
      
&lt;/head&gt;
&lt;body&gt;
<div id="wrapper">
    <div id="hedder">
        Northwood Web Design
    </div>
    
      
    <div id="nav">
        &lt;?php $this->load->view('includes/nav'); ?&gt;            
    </div>
    <div id="main">        
        &lt;?php $this->load->view($main_content); ?&gt;
    </div>
      <div id="right">
        &lt;?php $this->load->view('includes/right'); ?&gt;
        <br><br><br><br><br><br><br><br><br><br><br><br><br>
    </div>
    
      <div id="footer">
        Featured in the &lt;?php echo anchor_popup('http://www.webdesigners-directory.com','National Web Design Directory','alt="National Web Design Directory" title="National Web Design Directory"'); ?&gt;      
        
    </div>
</div>

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




Theme © iAndrew 2016 - Forum software by © MyBB