Codeigniter HMVC

编程入门 行业动态 更新时间:2024-10-25 12:23:43
Codeigniter HMVC - 两个模块将相同的变量名称传递给它们的视图并导致冲突(Codeigniter HMVC - Two modules passing the same variable name to their views and causing conflict)

我的安装中有两个模块。 两个模块的控制器传递一个名为的变量

$data['content']

对他们的看法。 此外,第一个模块的视图通过第二个模块运行

<?php echo Modules::run('module2'); ?>

之后应该显示其$ data ['content']变量的值。 不幸的是,当第一个模块的$ data内容被第二个模块的$ data替换时。 这对我来说非常不方便,所以我想知道是否有办法“保护”$ content变量并将它们保留在相关的模块中?

如果可能的话,我想避免重命名$ data ['content']。 我发现使用时不太完美的解决方案

$data(__CLASS__)

但我很好奇是否有可能不改变$ data ['content']。

I have two modules in my installation. Both modules' controllers pass a variable called

$data['content']

to their views. Also, the first module's view runs the second module via

<?php echo Modules::run('module2'); ?>

and after that is supposed to display values from its $data['content'] variable. Unfortunately, that's when the first module's $data content is substituted with the second module's $data. This is pretty inconvenient for me, so I would like to know if there is a way to "protect" the $content variables and keep them only within their associated modules?

I would like to avoid renaming $data['content'] if possible. I've found a not-so-perfect solution in using

$data(__CLASS__)

but I am curious if it is possible not to change $data['content'].

最满意答案

class Some extends MX_Controller{ public function __construct(){parent::__construct();} public function index(){ $this->load->view('template', array( //Primary template 'content' => 'some_index' // index view )); } public function _module_1(){ $this->load->view('module_1_view', array( //Module View : NO primary template '' => '' <= no need to load view here, only data )); } public function _module_2(){ $this->load->view('module_2_view', array( //Module View : NO primary template '' => '' <= no need to load view here, only data )); } }

-

的template.php

<html> <?php $this->load->view($content); ?> </html>

-

some_index.php

<html> //call modules <?php echo Modules::run('some/_module_1'); ?> <?php echo Modules::run('some/_module_2'); ?> //call module from another class <?php echo Modules::run('another_class/_module_1'); ?> </html> class Some extends MX_Controller{ public function __construct(){parent::__construct();} public function index(){ $this->load->view('template', array( //Primary template 'content' => 'some_index' // index view )); } public function _module_1(){ $this->load->view('module_1_view', array( //Module View : NO primary template '' => '' <= no need to load view here, only data )); } public function _module_2(){ $this->load->view('module_2_view', array( //Module View : NO primary template '' => '' <= no need to load view here, only data )); } }

-

template.php

<html> <?php $this->load->view($content); ?> </html>

-

some_index.php

<html> //call modules <?php echo Modules::run('some/_module_1'); ?> <?php echo Modules::run('some/_module_2'); ?> //call module from another class <?php echo Modules::run('another_class/_module_1'); ?> </html>

更多推荐

本文发布于:2023-08-04 05:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1409426.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Codeigniter   HMVC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!