如何创建具有基本设计风格的母版页(布局) [英] How to create Master Page(Layout) with base design style
问题描述
我是CodeIgniter的新人。我想创建母版页或布局与基本样式,将包含菜单,页脚等。我不想在所有页面写入重复内容,并自动加载所有页面。例如,我可以在asp.net中创建母版页或在asp.net mvc中创建布局。
假设你有一个html页面
< html>
< head>
< title> Hello World< / title>
< / head>
< body>
< div id =menu>
< li>< a href =#>首页< / a>< / li&
< li>< a href =#>关于< / a>< / li&
< li>< a href =#>联系人< / a>< / li>
< / div>
< div id =main-content>
<! - 这是动态部分 - >
< / div>
< div id =footer>
Copy Right 2013 Hello World
< / div>
< / body>
< / html>
您可以将其拆分为
1- header
2- menu
3-主要内容
4-页脚
你基本上
< html>
< head>
< title> Hello World< / title>
< / head>
< body>
在一个视图中称为view_header
然后你放
< div id =menu>
< li>< a href =#>首页< / a>< / li&
< li>< a href =#>关于< / a>< / li&
< li>< a href =#>联系人< / a>< / li>
< / div>
< div id =main-content>
在视图中调用view_menu
,然后输入
< / div>
< div id =footer>
Copy Right 2013 Hello World
< / div>
< / body>
< / html>
在视图中调用view_footer
然后在您的控制器
$ this-> load-> view('view_header');
$ this-> load-> view('view_menu');
$ this-> load-> view('YOUR_VIEW');
$ this-> load-> view('view_footer');
另一个解决方案,创建一个名为view_template_1.php的视图
< html>
< head>
< title> Hello World< / title>
< / head>
< body>
< div id =menu>
< li>< a href =#>首页< / a>< / li&
< li>< a href =#>关于< / a>< / li&
< li>< a href =#>联系人< / a>< / li>
< / div>
< div id =main-content>
<?php $ this-> load-> view($ content); >
< / div>
< div id =footer>
Copy Right 2013 Hello World
< / div>
< / body>
< / html>控制器中的
假设您想调用一个名为About的视图
$ data = array('content'=>'about');
$ this-> load-> view('view_template',$ data);
I'm new in CodeIgniter. I want to create Master Page or Layout with base style that will be contain Menu, footer and etc. I don't want to write repeating content in all pages and load it automatically for all pages. For example, I can create Master Page in asp.net or Layout in asp.net mvc. I'm sure I can do it in CodeIgniter.
解决方案 lets assume you have an html page
<html>
<head>
<title> Hello World </title>
</head>
<body>
<div id="menu">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</div>
<div id="main-content">
<!-- this is the dynamic part -->
</div>
<div id="footer">
Copy Right 2013 Hello World
</div>
</body>
</html>
you could split it into
1- header
2- menu
3- main content
4- footer
you basically put
<html>
<head>
<title> Hello World </title>
</head>
<body>
in one view called "view_header"
then you put
<div id="menu">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</div>
<div id="main-content">
in a view called "view_menu"
and then you put
</div>
<div id="footer">
Copy Right 2013 Hello World
</div>
</body>
</html>
in a view called "view_footer"
then in your controller
$this->load->view('view_header');
$this->load->view('view_menu');
$this->load->view('YOUR_VIEW');
$this->load->view('view_footer');
The other solution, which I see is better: create a view called view_template_1.php
<html>
<head>
<title> Hello World </title>
</head>
<body>
<div id="menu">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</div>
<div id="main-content">
<?php $this->load->view($content); ?>
</div>
<div id="footer">
Copy Right 2013 Hello World
</div>
</body>
</html>
in the controller lets say you want to call a view called About
$data = array('content'=>'about');
$this->load->view('view_template',$data);
这篇关于如何创建具有基本设计风格的母版页(布局)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!