Welcome Guest, Not a member yet? Register   Sign In
Finding it so hard to understand how to start.
#11

[eluser]rogierb[/eluser]
A little more info might be usefull, are the footer and header dynamic or just plain html?

If they are not dynamic, then use a template;-)
#12

[eluser]zutis[/eluser]
My way has a step missing ... here is the update:

Code:
function my_view($real_view_file, $data = array(), $switch = false)
   {
      $master_data['header']  = $this->load->view('header_view', $data, true);
      $master_data['content'] = $this->load->view($real_view_file, $data, true);
      $master_data['footer']  = $this->load->view('footer_view', $data, true);
      $this->load->view('master_template', $master_data, $switch);
   }

then you master_template would have

Code:
<?
       echo $header;
       echo $content;
       echo $footer;  
   ?>
#13

[eluser]SteveBluck[/eluser]
They are dynamic unfortunately. They change if the user is logged in or not.
#14

[eluser]rogierb[/eluser]
I would go with a general template and load the different views into it.

If you don't want to repeat yourself you can do something like
Code:
class Somecontroller extends Controller {
    var $data;
    var $header;
    var $footer;
    
    function __construct()
    {
        parent::Controller();
        $this->data['user_is_logged_or_not'] = 'true or false'

        $this->header = $this->load->view('header_view', $this->data, true);
        $this->footer = $this->load->view('footer_view', $this->data, true);        
    }

    function somehing() {
        $this->data['content'] = $this->load->view('content_view', $this->data, true);
    }

    function __destruct()
    {
        $this->load->view('template_view', $this->data);
    }
}

ofcourse this is just one of many methods
#15

[eluser]RJ[/eluser]
I have not personally tested this, but plan to in the future.

Code:
http://www.williamsconcepts.com/ci/codeigniter/libraries/template/index.html

Appears to cover all needs of a dynamic site template. Hope this helps.
#16

[eluser]ToddyBoy[/eluser]
@jedd - I'm getting confused with yours and @zutis' file names and locations as to what to put and where.

Here's my controller file called home.php (my default controller)

Code:
<?php

class Home extends Controller {

    function Home()
    {
        parent::Controller();
    }
    
    function index()
    {
        $this->load->view('header');
        $this->load->view('nav');
        $this->load->view('content');
        $this->load->view('footer');
    }

}

?>

As you can see, it's nice and simple. But, I would like to make things more like the code in previous posts, having dynamic content in the 'content' view. I would do something like this in the index function to achieve that:

Code:
function index()
    {
        $this->load->model('example');
        $data['query'] = $this->example->products();
        $this->load->view('header');
        $this->load->view('nav');
        $this->load->view('content', $data, TRUE);
        $this->load->view('footer');
    }

I can't get my head around your MY_Controller.php file, it's content, it's location and how it's used.
#17

[eluser]jedd[/eluser]
Okay .. well, remember that this is just one way of doing things. Some people approach the problem quite differently - using a templating system, or calling views from within views. I haven't played with the different template systems much, and I suspect my background (non-MVC, non-OOP) makes me stick with my current way. I also don't like calling views from within views, as I find the indirection unnecessarily confusing and harder to a) design, and b) trouble-shoot. Others, as I say, swear by this approach.

I mention this simply because it's like anything in IT - whichever path you go down first, is likely to be the way you'll do it forever.

Having said that ... your controller code:
Quote:
Code:
function index()
    {
        $this->load->model('example');
        $data['query'] = $this->example->products();
        $this->load->view('header');
        $this->load->view('nav');
        $this->load->view('content', $data, TRUE);
        $this->load->view('footer');
    }

Okay, so the differences in my approach are basically:
a) I call my header, nav and footer equivalents in [url="/wiki/MY_Controller"]MY_Controller[/url] (this is well documented in the CI User Guide - have a re-read of that section),
b) when I call my header/nav/footer views, I return the value into a variable ($this->data['top_bar_view'], etc) so that it will be visible in all my Controllers, and more importantly, in every view that I pass $this->data to (ie. all of them)
c) in a vanilla controller, I will simply generate my main content view using whatever custom load->view('controllername/thing') call, also loading that with the TRUE third flag, sending the output to $this->data['main_content_view'] and then I'll load my default view - the one that pretty much every page is made from, and that contains very little other than DIVs and echo's of the above generated views. I posted my default.php view file earlier in this thread.

Does that make it clearer?

If you are really stuck, PM me with an email address and I can zap you a tarball of my current far-from-finished but slightly enlightening project files with this stuff in it.
#18

[eluser]Mauricio de Abreu Antunes[/eluser]
Ok!
If i have this in MY_Controller:

Code:
$template['header']     = $this->load->view('header_view', $data, true);
$template['content']    = $this->load->view($view_to_show, $data, true);
$template['footer']     = $this->load->view('footer_view', $data, true);
$this->load->view('intranet_template', $view_to_show, $output);


I can echo $template['header'] in my intranet template.

But, if i have modules in my page? For example, new module in my home (after login).

Code:
$data['news'] = $this->news_model->return_news(); //Database call

If i need to add this in MY_Controller, how can i do? Like this?

Code:
$template['header']      = $this->load->view('header_view', $data, true);
$template['content']     = $this->load->view($view_to_show, $data, true);
//$template['news_module'] = HELP ME HERE[/b]$template['footer']      =
$this->load->view('footer_view', $data, true);
$this->load->view('intranet_template', $view_to_show, $output);


I need to load news_module in all pages and its dynamic.





Theme © iAndrew 2016 - Forum software by © MyBB