Welcome Guest, Not a member yet? Register   Sign In
loading a view file within another view file
#8

[eluser]OwanH[/eluser]
Quote:What about just using $this->load->view(‘login/form’) in the view file? Is this wrong (from an MVC point of view)?

It's not so much a matter of whether doing this is wrong or right, it's more a matter of your development approach. It's perfectly OK and feasible to have a view file loading another view file, i.e. views within views. In some cases however you may want to keep the tasks of loading your views within the controller methods. To give an example, the line of code I highlighted above,

Code:
$this->page_data['content'] = $this->load->view('forms/login', $form_data, true);

is actually a line of code from a webapp my business is developing. To explain the logic, I have a controller called User and there's a method called _login_page that loads the login page if the user if not logged in and they attempt to access the app. Now each page requires multiple views to be loaded, there's a header view, menu view, content view, and footer view. So my controller method handles the loading of all these views, using models and libraries to access data from the app's database and passing it on to the views. Where there is a need to load sub-views within any of these views, the controller method loads the sub-view, assigns it to a data variable so that the entire contents of the sub-view are passed to the view as data that the view can just output.

Now this approach suits my business' app fine because I have no more than two hierarchies of views when loading a page request, and for Ajax-based requests, no more than one hierarchy. If you need to go deeper than two hierarchies of views then you may prefer to load sub-views within the view files, although even then you can still delegate all the loading to the controller.

Like I said it's a matter of your development approach and what you or the development team may consider to be a best practice.


Messages In This Thread
loading a view file within another view file - by El Forum - 12-22-2008, 02:00 PM
loading a view file within another view file - by El Forum - 12-22-2008, 03:51 PM
loading a view file within another view file - by El Forum - 12-22-2008, 07:07 PM
loading a view file within another view file - by El Forum - 12-22-2008, 07:41 PM
loading a view file within another view file - by El Forum - 12-22-2008, 07:52 PM
loading a view file within another view file - by El Forum - 12-22-2008, 08:10 PM
loading a view file within another view file - by El Forum - 12-23-2008, 02:58 AM
loading a view file within another view file - by El Forum - 12-23-2008, 04:29 AM
loading a view file within another view file - by El Forum - 12-23-2008, 04:52 AM
loading a view file within another view file - by El Forum - 12-23-2008, 06:28 AM
loading a view file within another view file - by El Forum - 12-23-2008, 04:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB