Question

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.

https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc

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"><!--Content wrapper-->

    <?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 
    }

    ?>
</div><!-- End contentwrapper -->
</div><!-- End #content -->
Était-ce utile?

La solution

here is one way you can use for body content of view take advantage of OOP extend your controllers with MY_Controller create MY_Controller class under application core.

class MY_Controller extends MX_Controller { 
     // not using Modular extentions then extend with CI_Controller

    function __construct(){
          parent::__construct;
    }

    function build($view=null,$data=array()){

          $load_view = 'supr/body_unknown_view';

          if(strlen($view))
          {
               $load_view = 'supr/cpanel/pages/' . $view;
          }

        $body = $this->load->view($load_view,$data,TRUE);

        $this->load->view('supr/cpanel/body_content',array('body'=>$body));

    }

}

//blog controller
class blog extends MY_Controller { 


        function __construct(){
              parent::__construct;
        }

        function index(){
           //anydata
           $data['blog_content'] = 'blog content';
           $this->build('blog_view',$data);
        }

    }

<!--Body content-->
<div id="content" class="clearfix">
    <div class="contentwrapper"><!--Content wrapper-->

    <?php echo $body; ?>

</div><!-- End contentwrapper -->
</div><!-- End #content -->
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top