Welcome Guest, Not a member yet? Register   Sign In
Modular Separation.
#1

[eluser]xtremer360[/eluser]
I'm using the HMVC modular separation for my Codeigniter application and trying to figure out how I can attempt this with my template I have set up. There could possibly be a better way to handle this and I'm not sure of it but if anyone can suggest one I'd be all ears. This is my current file system. Supr as noted as a a folder below is the current theme template I am using.

Inside each module controller exists a variable called $view_file. This is the variable this is passed to the body content view page and tells it which view file to display inside my content wrapper in my control panel.

What I need to figure out is how to add on a file_exists function to the if statement so that it looks to see if the value for the variable can see if that file exists but not sure how to accomplish this with this HMVC module separation framework. The reason why I need help understanding how to do this is because I don't know how to have it know which module view to look into.

I have also included my code for the body content view which contains an if statement to find out which file it needs to load.



Code:
application/
    modules/
        blog/
            controllers/
                blog.php
            models/
                blog_model.php
            views/
                blog_view.php
        dashboard/
            controllers/
                dashboard.php
            models/
                dashboard_model.php
            views/
                dashboard_view.php
    views/
        supr/
            cpanel/
                header.php
                footer.php
                body_content.php

<!--Body content-->
<div id="content" class="clearfix">
    <div class="contentwrapper">&lt;!--Content wrapper--&gt;

    &lt;?php

    if ((empty($view_file)) || (!isset($view_file)) || (trim($view_file) == '')) //add file exists to if statement for module view file being requested
    {
        $this->load->view('supr/body_unknown_view');
    }
    else
    {
        $this->load->view('supr/cpanel/pages/' . $view_file);  // Change to module speration view file
    }

    ?&gt;
</div>&lt;!-- End contentwrapper --&gt;
</div>&lt;!-- End #content --&gt;

https://bitbucket.org/wiredesignz/codeig...sions-hmvc
#2

[eluser]Harold Villacorte[/eluser]
If I understand your question correctly you can just add the module name to the data array. Something like this:
Code:
$data['module'] = 'blog';
Then the variable $module is available to the template.
#3

[eluser]PhilTem[/eluser]
I'm not sure if I get your question right, either, but HMVC (as long as you're using @wiredesignz HMVC) will always look in the module's view folder for the given view if loaded via $this->load->view(), so there's no need to pass the module name to it.
#4

[eluser]InsiteFX[/eluser]
The Modules::$locations array may be set in the application/config.php file. ie:
Code:
&lt;?php
$config['modules_locations'] = array(
APPPATH.'modules/' => '../modules/',
);
#5

[eluser]xtremer360[/eluser]
[quote author="PhilTem" date="1359361569"]I'm not sure if I get your question right, either, but HMVC (as long as you're using @wiredesignz HMVC) will always look in the module's view folder for the given view if loaded via $this->load->view(), so there's no need to pass the module name to it.[/quote]

Well something isn't work because it keeps loading my body_unknown which also gets loaded when it can't find the file being requested.

This is my body_content.php file. Which is in the application views folder inside of the components folder. I am trying to do a search for the dashboad_view.php folder which is in the application modules in the dashboard module in the views folder of that.

Code:
/application
    /modules
        /dashboard
            /controllers
                dashboard.php
            /views
                dashboard_view.php
    /views
        index_view.php
        components/
            body_content_view.php

Code:
&lt;!--Body content--&gt;
<div id="content" class="clearfix">
    <div class="contentwrapper">&lt;!--Content wrapper--&gt;

  &lt;?php
  if ($this->functions_model->null_check($view_file) === TRUE)
  {
   $this->load->view('components/body_unknown_view');
  }
  else
  {
   if (file_exists($view_file))
   {
    $this->load->view($view_file);
   }
   else
   {
    $this->load->view('components/body_unknown_view');
   }
  }
  ?&gt;
  
</div>&lt;!-- End contentwrapper --&gt;
</div>&lt;!-- End #content --&gt;
#6

[eluser]xtremer360[/eluser]
Any ideas?
#7

[eluser]PhilTem[/eluser]
Oh, I see. So, your problem either arises from any of the if-lines. I guess, the problem is the second if.

Since all paths are relative to index.php, and you're looking for a view file, it will always fail, unless you have

Code:
if ( file_exists(APPPATH . 'views/' . $view_file) )
{
  $this->load->view($view_file)
}
//...

since your code is looking for the view-files located relative to index.php, not the views-folder. See the problem causing line?

Otherwise, if this didn't solve your problem, it may be something in your model call, that will always return 0, 1 or something else than (boolean) TRUE.
#8

[eluser]xtremer360[/eluser]
I know its that if statement. The problem is figuring out the difference between having it look in the module's view folder as oppossed to the regular view folder.

By this I mean lets say you go to my dashboard which loads the index file just fine with the header component and the footer component and loads the body content component.

At this point it'll be in the applications/views/index_view.php file piecing together the template.

The problem is if you are loading the dashboard or any of the other modules and pass say the view file variable as 'dashboard_view' then it needs to look for that file somehow in the application/modules folder and hopefully find it there.

I'm just lost on how to figure out how to tell it to look there.
#9

[eluser]PhilTem[/eluser]
Aaaah, I finally get it Wink

Then your code should be something like this (haven't tested it, so it may be a little faulty, but should hint you towards the right direction)

Code:
if ( $this->functions_model->null_check($view_file) === TRUE )
{
    $content = $this->load->view('components/body_unknown_view', NULL, TRUE);
}
else
{
    $skip = FALSE;
    
    foreach ( Modules::$locations as $location => $offset )
    {
        if ( ! is_dir($base = $location . $this->router->fetch_module()) )
        {
            continue;
        }
        
        if ( file_exists($base . 'views/' . $view_file) )
        {
            $content = $this->load->view($view_file, NULL, TRUE);
            
            $skip = TRUE;
            
            break;
        }
    }
    
    if ( ! $skip )
    {
        $content = $this->load->view($view_file, NULL, TRUE);
    }
}

echo $content;

There could be some errors with directory-separators, but I don't have a PHP-environment around, so unfortunately, I cannot test it right now Wink
#10

[eluser]xtremer360[/eluser]
Why do you have the extra parameters inside the load view command?




Theme © iAndrew 2016 - Forum software by © MyBB