Welcome Guest, Not a member yet? Register   Sign In
In the interests of DRY
#10

[eluser]JoostV[/eluser]
You can also just use nested views. That way, you don't need to repeatedly load view from every controller.

1. Just call the main view from your controller:
Code:
// Define a custom subview for this page
$master_view['sub_view'] = 'my_subview';
$this->load->view('master_view', $master_view);

2. In your master view file you can load all subviews that you need:
Code:
$this->load->view('header');
$this->load->view('navbar');

// This is where we will load our custom subview
$this->load->view($my_subview);

$this->load->view('footer');

Make sure to pass all data that your subviews will need in variable $master_view. E.g., if you need to set up a navbar you can do that in the __construct of a special navbar model and store it in $master_view['navbar']. Autolad the model and $master_view['navbar'] will be created automatically for every page.


Messages In This Thread
In the interests of DRY - by El Forum - 01-12-2009, 08:16 PM
In the interests of DRY - by El Forum - 01-13-2009, 12:14 AM
In the interests of DRY - by El Forum - 01-13-2009, 12:38 AM
In the interests of DRY - by El Forum - 01-13-2009, 12:51 AM
In the interests of DRY - by El Forum - 01-13-2009, 12:57 AM
In the interests of DRY - by El Forum - 01-13-2009, 02:17 AM
In the interests of DRY - by El Forum - 01-13-2009, 07:47 PM
In the interests of DRY - by El Forum - 01-13-2009, 11:38 PM
In the interests of DRY - by El Forum - 01-14-2009, 12:02 AM
In the interests of DRY - by El Forum - 01-14-2009, 06:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB