简体   繁体   English

hmvc codeigniter

[英]hmvc codeigniter

I have learned the basics of codeigniter and now learning the modules. 我已经学习了codeigniter的基础知识,现在学习了这些模块。

My problem : I have made two folders inside the modules folder, first_module and second_module . 我的问题:我在modules文件夹中创建了两个文件夹, first_modulesecond_module

In the first_module inside the controller my code : 在控制器内的first_module我的代码:

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

first_module_view page code : first_module_view页面代码:

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

second_module controller page : second_module控制器页面:

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

second_module_view page: second_module_view页面:

<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. 我试图使用second_module的控制器部分查看first_module视图中的第二个模块视图,但这不起作用。
Individually both codes are working fine but Modules::run() doesn't seems to work. 单独两个代码都工作正常,但Modules::run()似乎不起作用。

Am I missing something? 我错过了什么吗?

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. 只需从模型中传入控制器中生成的变量即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM