【发布时间】:2012-06-30 19:02:37
【问题描述】:
我已经学习了 codeigniter 的基础知识,现在正在学习模块。
我的问题:我在模块文件夹中创建了两个文件夹,first_module 和 second_module。
在控制器内的first_module 中我的代码:
<?php
class First_module extends MX_Controller {
public function index()
{
$this->load->view('first_module_view');
}
}
?>
first_module_view页面代码:
<html>
<body>
<h1> hey this is first module </h1>
<?php
echo Modules::run('second_module/second_module');
?>
</body>
</html>
second_module 控制器页面:
<?php
class Second_module extends MX_Controller {
public function index()
{
$this->load->view('second_module_view');
}
}
?>
second_module_view页面:
<html>
<body>
<h1> hey this is second module </h1>
</body>
</html>
我正在尝试使用 second_module 的控制器在 first_module 视图中部分查看第二个模块视图,但这不起作用。
单独两个代码都可以正常工作,但Modules::run() 似乎不起作用。
我错过了什么吗?
【问题讨论】:
-
只是为了确认你能看出是在配置中设置的 Modules::$locations 数组吗?
-
嗯.. 我在配置文件中设置了
$config['modules_locations'] = array( APPPATH.'modules/' => '../modules/', ); -
已解决... :) 我没有在
echo Modules::run('second_module/second_module');中包含索引它在代码中正确执行:-echo Modules::run('second_module/second_module\index'); -
哦,你真的不想从另一个控制器调用一个控制器。这就是为什么它被称为模块化分离。您可以通过与其他模块(first_module/first_module_view.php)引用它们来共享模型和视图。如果你开始从另一个控制器调用一个控制器,你会很头疼。
-
我倾向于同意 Thom,这就是为什么首先创建 MVC 来分离东西......无论如何,如果你绝对需要这个,不要将 html、head 和 body 标签放入第二个视图,因为这会生成一个语义不正确的网站
标签: php model-view-controller codeigniter module hmvc