我的安装中有两个模块。 两个模块的控制器传递一个名为的变量
$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>更多推荐
发布评论