Welcome Guest, Not a member yet? Register   Sign In
MVC Hierarchy question.
#5

[eluser]smalter[/eluser]
EDIT: Ok. I think that you are better going to understand with the exemple.
By thinking, i want to include a *controller* in my other views... But I know that it is not a solution.


Thanks for your help!

Exemple:
Code:
// Shop: Main Controller
class Shop extends Controller {
  function shop {
    parent::Controller();
    // Load somes library, plugins or helper
    $this->load->helper('blabla');
    $this->load->library('blabla');
    $this->load->model('my_model');
  }

  function index() {
    $data['title'] = 'This is my shop!';
    $data['list_item'] = $this->my_model->lastentries();
    $this->load->view('homepage', $data);
}
}

// Homepage: Main view
// Load header view
<?=$this->load->view('header', $data)?>
<?=$this->load->view('content_of_my_page', $data)?>

// Display last entries in the bottom of the page
<?=$this->load->view('lastentries_view', $data)?>
<?=$this->load->view('footer', $data)?>

// Lastentries_view: view
<?
<?php foreach($list_item as $item): ?>
echo $item->lastentries();
<?php endforeach;?>
?>

Ok, it is working.

But now, i decide to include "lastentries_view" in an other view "contact.php", on the top.

I make a new view and controller:
Code:
// Contact controller
class Contact extends Controller {
  function contact {
    parent::Controller();
    // Load somes library, plugins or helper
    $this->load->helper('blabla');
    $this->load->library('blabla');
  }

  function index() {
    $data['title'] = 'Contact page';
    $data['content'] 'Content of my contact page';
    $this->load->view('contact', $data);
}
}

// Contact: view

// Load header view
<?=$this->load->view('header', $data)?>

// Display last entries before the content
<?=$this->load->view('lastentries_view', $data)?>

<?=$content;?>
<?=$this->load->view('footer', $data)?>

In the second exemple, the value "$list_item" used in "lastentries_view" doesn't exist.
This is make an error.

How I can get organized to be able to move a view (lastentries_view) and display it in different other views, but by keeping the access to variables? (Homepage on the bottom, Contact page on the top,...)

Cheers. Smile


Messages In This Thread
MVC Hierarchy question. - by El Forum - 12-25-2007, 05:52 PM
MVC Hierarchy question. - by El Forum - 12-25-2007, 10:38 PM
MVC Hierarchy question. - by El Forum - 12-26-2007, 02:13 AM
MVC Hierarchy question. - by El Forum - 12-26-2007, 04:12 AM
MVC Hierarchy question. - by El Forum - 12-26-2007, 04:25 AM
MVC Hierarchy question. - by El Forum - 12-26-2007, 05:26 AM
MVC Hierarchy question. - by El Forum - 12-26-2007, 09:03 PM
MVC Hierarchy question. - by El Forum - 12-26-2007, 11:59 PM
MVC Hierarchy question. - by El Forum - 12-30-2007, 05:30 PM



Theme © iAndrew 2016 - Forum software by © MyBB