[英]How to customize master template concept in codeigniter 3.0?
I am new in Codeigniter 3.0. 我是Codeigniter 3.0的新手。 So master page concept how used in Codeigniter 3.
因此,母版页概念如何在Codeigniter 3中使用。
I want to make the admin panel master page so I don't rewrite header, footer code. 我想制作管理面板母版页,这样就不会重写页眉,页脚代码。 I also want to customize the title.
我也想自定义标题。
How to do it? 怎么做?
First I would create something like this below in a controller. 首先,我将在下面的控制器中创建类似的内容。 You can set your content page in a variable like below and then pass it to your admin template.
您可以在下面的变量中设置内容页面,然后将其传递到管理模板。 Like in the example view.
就像在示例视图中一样。 Just a example below though.
下面只是一个例子。 also auto load url helper.
还会自动加载网址帮助器。
<?php
class Welcome extends CI_Controller {
public function index() {
// You should be able to pass data as normal
$data['title'] = 'Welcome to CodeIgniter'; // You can change the title on every controller you create.
$data['template_page'] = 'welcome_message'; // This dashboard would be name of a view and common name a folder.
$this->load->view('template', $data);
}
}
Example 2 Controller 示例2控制器
<?php
class Dashboard extends CI_Controller {
public function index() {
// You should be able to pass data as normal
$data['title'] = 'Dashboard'; // You can change the title on every controller you create.
$data['template_page'] = 'common/dashboard'; // This dashboard would be name of a view and common name a folder.
$this->load->view('template', $data);
}
}
Views > template.php 视图> template.php
<?php
$this->load->view('common/header');
$this->load->view($template_page);
$this->load->view('common/footer');
?>
Header views > common > header.php 标题视图>通用> header.php
<!DOCTYPE html>
<html>
<head>
// meta tags
<title><?php echo $title;?></title>
// css links
// other js links
</head>
<body>
Content lets say dashboard views > common > dashboard.php 内容可以说仪表板视图>通用> dashboard.php
<h1>Hello World</h1>
Footer views > common > footer.php 页脚视图>常见> footer.php
// bootstrap scripts.
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.