HMVC and Views in folders (Codeigniter)
I am using Tank Auth library in Codeigniter with HMVC and the entire tank auth mvc files are in its own module called 'auth'. tank auth loads a view (domain.com/application/modules/auth/views/auth/login_form.php) found inside a folder (auth) using:
$this-&开发者_如何学Cgt;load->view('auth/login_form', $data);
As far as I know the above code will load login_form.php inside the auth folder properly without HMVC. However with HMVC, I need the following code to get the view to load:
$this->load->view('auth/auth/login_form', $data);
Is there a setting that we should change so we dont have to refer to the view file by (module name)/(views folder name)/(view filename) ? Or is this perfectly normal and most people does it this way?
It seems troublesome that I have to add the module folder name 'auth' to every view() function call, and change all of them should I change the name of the module folder.
Assuming you're using Modular Extensions - HMVC:
If you have auth
set up as a module already, you can just call:
$this->load->view('login_form', $data);
The file /views/login_form.php
will be loaded from within the current module. This applies to models, language files, libraries etc. Think of the module as its own application, this is what you would normally do.
Additionally, to load a file from another module or a controller outside the module's directory, you can use $this->load->view('auth/login_form');
If the file is not found, it will check the other module paths including the default directory. This may or may not be the way other HMVC packages work, I'm not sure - but it's the way MX works.
精彩评论