3

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->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.

tereško
  • 58,060
  • 25
  • 98
  • 150
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830

1 Answers1

3

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.

Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
  • I have followed the 12 step installation of HMVC at https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home . Do I need to do additional things to set up auth as a module? auth is already in the modules folder, along with its views and controllers etc. I read about extending MY_controller, does it matter that I'm currently extending CI_controller? – Nyxynyx Jun 07 '11 at 17:56
  • Btw, I'm trying to load /views/auth/login_form.php in the 'auth' module. Right now it seems like i can only call it with $this->load->view('auth/auth/login_form', $data); – Nyxynyx Jun 07 '11 at 17:58
  • Do you have *all* the auth files in a module, or are some of them still in the default directories? And to make sure: Are you calling this from a controller within the auth module? Why do you have a subdirectory within `auth/views/` called `auth`? You don't need it, move the view files right into `/views` within the module. – Wesley Murch Jun 07 '11 at 17:59
  • Yup all the auth files are in a module, none left in the default directories. I'm calling the views from within the auth module.. controller is application/modules/auth/controllers/auth.php – Nyxynyx Jun 07 '11 at 18:02
  • There is a subdirectory in the views called 'auth' because there is another subdirectory in views called 'email' to differentiate the authentication views from the email templates or something... These subdirectories came with the tank_auth lib – Nyxynyx Jun 07 '11 at 18:03
  • Then in that case you'll have to use `$this->load->view('auth/login_form')`, there's no way around it - this is what you'd normally do in CI with that directory structure. Consider changing it and moving the front-end views into the root of `/views`. – Wesley Murch Jun 07 '11 at 18:05
  • ok i'll just remove them out of the auth subdirectory in views. Solves the problem. Thanks! – Nyxynyx Jun 07 '11 at 18:08