[eluser]momsenmeister[/eluser]
Hi everybody,
starting with CI, I had problems to nest
views within
views in a clean way.
So I read a lot about it, and decided to use the following approach:
- load the basic layout-
views within the controller
- within the layout-
views, load partials as
nested views via $this->load->view()
This works for me as long as there is no business logic involved.
But now I come to the point, where my project becomes more complex.
My question is, how I can avoid constructs like this in
views:
(View: basic_layout.php)
Code:
$this->load->view('header');
$this->load->view('navigation');
if ($access == true)
{
switch($content_to_show)
{
case 'startpage': ...
case 'account': ...
case 'impressum': ...
default: ...
}
}
$this->load->view('footer');
My problem here is, that I only want to define the basic layout ONCE.
So I don't want to load header, navigation and footer from the controller every time.
This should also behave the same with partials (and partials within partials etc.).
But as my
views might contain loops for example, I can't just preload them in a variable in the controller.
So I more or less, all of my controllers look like this:
Code:
$data[access] = 'private';
$data['content'] = 'account';
$this->load-view('basic_layout', $data);
I don't think that it makes a lot of sense to always load the view basic_layout, but how can I avoid this in a clean way?
How do you structure complex
nested views, how do you seperate the business logic?
Thanks a lot!