[eluser]Rick Jolly[/eluser]
The way a developer loads a view and its data is a matter of personal preference and choice is good. I just wanted to make a few of points in favor of CI’s current implementation and maybe provoke a bit of thought and discussion.
1) Coupling a View to its Data
Coupling a view to its data when loading is good style. As we know, with CI you can load a view and its data all at once:
Code:
$this->load->view(‘view’, $data);
$view_part = $this->load->view(‘view_part’, $data, true);
When setting view variables using $this->load->vars() or other syntax, there is no traceable link between the view and its variables. View variables could be loaded throughout the code, making it difficult to read and maintain.
2) Locally Scoped Variables for Partial Views
Another advantage to the $this->load->view(‘view_part’, $data, true); method: it allows locally scoped variables. When setting view variables in a global way (like when using $this->load->vars(); and other custom methods) every partial view must share the same variables.
3) A View is a View
CI treats a view as a view. You load views within views (partials/fragments/blocks) in the same generic way as a regular view. Some developers prefer to differentiate between views and nested views by using different loading syntax. I find it confusing to make those differentiations, and there is additional syntax to remember.