【发布时间】:2011-03-29 02:54:03
【问题描述】:
我正在尝试将 HTML/CSS 文件转换为模板。我寻求帮助,但在那篇文章中没有收到任何建议,但我试图找出一种创建模板的方法。我在这样做时遇到了一些小故障。我的控制器有 main.php 文件,它是网站的主页,我已经注册了页眉、页脚和其余部分保持不变的位置,只是页面加载时主要内容发生了变化。
我在视图文件夹中有以下模板:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><?= $title ?></title>
<style type="text/css" >
@import url('<?=base_url()?>/includes/front.css');
@import url('<?=base_url()?>/images/');
</style>
</head>
<body>
<div id="container">
<div id="header">
<?= $logo ?> <!--This is an image tag to display the image on the template -->
<?= $topnav ?>
</div>
<div id="menubar">
<?= $menulist ?>
</div>
<div id="maincontent">
<?= $flashcontent ?>
<?= $resources ?>
<?= $registerForm ?>
</div>
<div id="footer">
<div>
<?= $footertable1 ?>
</div>
</div>
</div>
</body>
</html>
在
div id = 主要内容
这是在网站加载时会发生变化的 div 标签。在我的模板中,我包含了
<?= $flashcontent ?> <?= $resource ?> and <?= registerForm ?>
flashcontent 和资源应该在主页中,并且当我单击主页中的注册时应该显示 registerForm。我一直在阅读代码点火器中的模板用户指南,但我无法理解如何使这个动态。请帮我解决这个问题。
这是配置文件夹中的template.php。
$template['active_group'] = 'default';
$template['default']['template'] = 'template.php';
$template['default']['regions'] = array(
'title',
'logo' => array(
'content' => array(''),
'name' => 'Logo',
'wrapper' => '<img>',
'attributes' => array('id' => 'logo')
),
'topnav' => array(
'content' => array(),
'name' => 'Topnav',
'wrapper' => '<div>',
'attributes' => array('id' => 'topnav', 'class' => 'topnav')
),
'menulist' => array(
'content' => array('<li>
<a href="#"> Home </a>
<a href="#"> Generator </a>
<a href="#"> News </a>
<a href="#"> Forum </a>
<a href="#"> About </a>
<a href="#"> Feedback </a>
</li>'),
'name' => 'Menulist',
'wrapper' => '<ul>',
'attributes' => array('class' => 'menulist')
),
'flashcontent' => array(
'content' => array(''),
'name' => 'Flashcontent',
'wrapper' => '<div>',
'attributes' => array('id' => 'flashcontent')
),
'resources' => array(
'content' => array(''),
'name' => 'Resources',
'wrapper' => '<div>',
'attributes' => array('id' => 'resources')
),
'registerForm' => array(
'content' => array(),
'name' => 'Registerform',
'wrapper' => '<div>',
'attributes' => array('id' => 'registerForm')
),
'footertable1' => array(
'content' => array('<ul>
<li> <a href="../main">Home</a>
<a href="#">News & Events</a>
<a href="#">Forum</a>
<a href="#">About us</a>
<a href="#">Contact us</a>
<a href="#">Terms of use</a>
<a href="#">Privacy policy</a>
<a href="#">Site map</a>
</li>
</ul>'),
'name' => '',
'wrapper' => '<div>',
'attributes' => array('id' => 'footertable1')
)
);
$template['default']['parser'] = 'parser';
$template['default']['parser_method'] = 'parse';
$template['default']['parse_template'] = FALSE;
提前致谢。
【问题讨论】:
标签: php model-view-controller codeigniter