我想使用通用页眉和页脚前端/通用页眉和页脚后端在codeigniter HMVC。请帮帮我。
你所要做的就是创建一个模块其中可以有你的admin控制器你可以为admin/backend创建页眉和页脚控制器然后你也可以做同样的事情但是只需要为front
重命名模块Modules::run('folder/folder/controllername/function');
或on you view
<?php echo Modules::run('folder/folder/controllername/function');?>
Doc的https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc
例如admin后端模块
application > modules
application > modules > admin
application > modules > admin > controllers > common
application > modules > admin > controllers > common > Header.php
application > modules > admin > controllers > common > Footer.php
application > modules > admin > controllers > example > Welcome.php
application > modules > admin > views > common > header.php
application > modules > admin > views > common > footer.php
application > modules > admin > views > example > welcome.php
URL示例http://localhost/project/index.php/example/welcome
Controller Admin示例
<?php
class Welcome extends MX_Controller {
public function index() {
$data['header'] = Modules::run('admin/common/header/index');
$data['footer'] = Modules::run('admin/common/footer/index');
$this->load->view('example/welcome_message', $data);
}
}
Admin Header Controller
<?php
class Header extends MX_Controller {
public function index() {
// Create a header view in the module folder view
return $this->load->view('common/header');
}
}
Admin Footer Controller
<?php
class Footer extends MX_Controller {
public function index() {
// Create a footer view in the module folder view
return $this->load->view('common/footer');
}
}
HMVC视图示例
<?php echo $header;?>
Your Content
<?php echo $footer;?>
或
<?php echo Modules::run('admin/common/header/index');?>
Your Content
<?php echo Modules::run('admin/common/footer/index');?>
当你需要改变HMVC的路由时
$route['default_controller'] = 'frontend/common/home/index';
$route['admin'] = 'admin/common/login/index';
$route['somename'] 'module/folder/controller/function';
$route['somename/edit/(:any)'] 'module/folder/controller/function/$1';
$route['somename/edit/(:any)/(:any)'] 'module/folder/controller/function/$1/$2';