Welcome Guest, Not a member yet? Register   Sign In
HMVC View Partials - Best Practices
#1

[eluser]ilumos[/eluser]
Hi Guys,

I'm using Wiredesignz's HMVC extension with CI 2.1.2 and I'm sure there's a better way to render view partials than how I'm doing things.

I feel I'm repeating too much code, and making my modules not re-usable.

Any comments/suggestions welcomed.

Code:
\application
   \modules
      \user
         \controllers
            user.php
         \models
            users_model.php
         \views
            profile.php
   \views
      container.php
      header.php
      footer.php


application/modules/user/controllers/user.php:
Code:
class User extends MX_Controller {

function profile($user_id)
{
  $layout_data['page_title'] = 'Profile';

  $content_data['user_details'] = $this->Users_model->get_user($user_id);

  $layout_data['content'] = $this->load->view('profile', $content_data, TRUE); // load view into content variable

  $this->load->view('container', $layout_data);
}


application/modules/user/views/profile.php:
Code:
<h1>&lt;?php echo $user_info['username']; ?&gt;</h1>
// etc ...


application/views/container.php:
Code:
<!DOCTYPE html>
&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;&lt;?php echo $page_title ?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;?php $this->load->view('header'); ?&gt;
  &lt;?php echo $content; ?&gt;
  &lt;?php $this->load->view('footer'); ?&gt;
&lt;/body&gt;
&lt;/html&gt;

Many thanks in advance







#2

[eluser]ZaLiTHkA[/eluser]
Why don't you put your common functions into a different module and run them with this:
Code:
Modules::run('module/controller/method', $param, $...);

I get the idea that's going to give you the DRY idea you're looking for here. Have a look at the BitBucket HMVC wiki page for more defails.




Theme © iAndrew 2016 - Forum software by © MyBB