avinashse
avinashse

Reputation: 1460

hmvc codeigniter

I have learned the basics of codeigniter and now learning the modules.

My problem : I have made two folders inside the modules folder, first_module and second_module.

In the first_module inside the controller my code :

<?php
    class First_module extends MX_Controller {
    public function index()
    {
        $this->load->view('first_module_view');            
    }
}
?>

first_module_view page code :

<html>
<body>
    <h1> hey this is first module </h1>
    <?php 
        echo Modules::run('second_module/second_module');
    ?>
</body>
</html>

second_module controller page :

<?php
class Second_module extends MX_Controller {
    public function index()
    {
        $this->load->view('second_module_view');
    }
}
?>

second_module_view page:

<html>
<body>
    <h1> hey this is second module </h1>
</body>
</html>

I am trying to partially view the second module view in the first_module view using the second_module's controller, but that is not working.
Individually both codes are working fine but Modules::run() doesn't seems to work.

Am I missing something?

Upvotes: 3

Views: 1729

Answers (1)

Kev Price
Kev Price

Reputation: 797

I am aware that you have found your solution and this does not answer the exact question that you asked, however, I would usually do something like that in this way:

       <?php
            class First_module extends MX_Controller {
            public function index()
            {
                 $content = array();

                //send content array to 2nd view and return everything as a string to be added as content to the first view

               $content["second_view"] = $this->load->view('second_module_view',$content,true);

               $this->load->view('first_module_view',$content);            
            }
        }
        ?>

First module view then becomes:

<html>
<body>
    <h1> hey this is first module </h1>
    <?php 
        echo $second_view;
    ?>
</body>

I've not worked with modules specifically, however this is how I would do it with controllers and views. I would do what I can to limit the calls to models and modules from within the view. Just pass in variables generated in the controller from your models.

Upvotes: 1

Related Questions