• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I create a nested view within a nested view?

#13
(09-26-2017, 03:54 PM)codeguy Wrote: Thanks for the encouraging reply. But I am confused that I see no data being transferred to your views. Like I'd expect something like . .

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

. .  perhaps preceded by a line like . .

$modRetArr['profile_data']=$this->M_profiles->get_profiles_data($params);

How do the views get the data? Is what you posted a full controller?

A few hrs later ***************** after studying your reply several times I wonder if perhaps the view load stmts did not require data because it was loaded into the views earlier. If so could you show that part possibly? Or maybe you thought I understood that part already and didn't need to show it. Or maybe they didn't use any dynamic data. I'm probably missing something simple and fundamental. Thanks for your patience.

Sorry I missed that post of yours. Any data is passed to the very first view. Views themselves still check to see if the data exists and if not deals with is smoothly, so there is no chance of errors showing if data is NULL or missing.

I recall that I used to pass data to all the views separately under the mistaken belief that the data passed to a view was removed once the view was processed. When I discovered this was not the case I carried on for a while passing view data manually to each view. After a while though it dawned on me what a waste of time this was. Now I simply load all the data into one variable and pass it to the very first view. I probably should load it into the view vars as described earlier by someone, but I have never had a problem passing it all the the header view, and having it all available to all other views.

My first view is always the header_view with the HTML, additional css, meta tags etc. The next is usually the main_menu_view with navigation and active states on the current page options etc. My page layouts I do in my own template library and set the page_data variables in my controller with library setters etc.

In fact, I now quite like that the view data is not deleted, and am hoping this will not change in CI4.

This approach makes changing the site template or design very easy to do, as I am only dealing with HTML layouts and css, never logic or data processing of any sort.

Hope that helps,

Paul.

PS I am very careful though to only pass the data that is required. So I always try to define the fields in my models using select statements rather than the quicker but dirtier method of relying on the fact that the query builder, if not told, will select all by default. Those are called by libraries that format the dates, currencies, etc. Finally any fields that need cleaning are done in the libraries, so the view files are as clean of php as possible, except of course for loops and basic if statements.
Reply


Messages In This Thread
RE: How do I create a nested view within a nested view? - by PaulD - 09-28-2017, 10:30 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.