Welcome Guest, Not a member yet? Register   Sign In
How do I create a nested view within a nested view?
#4

I often open views within views. I see nothing wrong with a view that looks something like:

View example
Code:
<h1><?php echo $user_name; ?></h1>

$this->load->view('partials/profile_view');

$this->load->view('partials/forms/add_profile_info_view');

$this->load->view('partials/adverts/upgrade_account_view');

<?php foreach ($options as $option) { ?>
     $this->load->view('partials/options/'.$option['option_url']);
<?php } ?>

As long as the controller is collecting all the data, libraries or models are performing all the business logic and database calls seperately, and the data is loaded into the view vars, every view will have access to all the data. Now when I want to change one of the options(say) from the many options available, I just alter one view file for that options partial.

I would use a template library of my own making to add header, footer, sidebar etc page layout bits and bobs. But in this example profile page many partials could be called.

I find this is very efficient. In a todo list I did recently each row of the table of todo's was calling a partial task view to display the task. In a recent calendar each day was calling a day view that did the layout of the day contents. In a shopping cart I did recently, each item in the basket was displayed with a basket_item view.

Efficient, dry, perfectly acceptable and still works incredibly quickly. It is normally my js and css that slows a page load down, never CI doing the work in the background.

Hope that helps,

Paul
Reply


Messages In This Thread
RE: How do I create a nested view within a nested view? - by PaulD - 09-26-2017, 11:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB