常量定义
define('MY_DATE',date('Y-m-d h:i:s',time()));
// 定义反斜线常量
define('DS', DIRECTORY_SEPARATOR);
//定义根目录常量
define('ROOT_PATH', $_SERVER['DOCUMENT_ROOT'] .'/0410'.'/web1');
//定义数据目录
define('DATA_PATH', ROOT_PATH.'/Data');
//定义模板目录
define('TMPL_PATH',ROOT_PATH.'/template');
// 定义公共目录
define('TMPL_PATH_PUBLIC',TMPL_PATH.'/public');
//定义静态资源目录
define('STATICE_PATH',ROOT_PATH.'/static');
define('STATICE_CSS_PATH',STATICE_PATH.'/css');
define('STATICE_IMAGES_PATH',STATICE_PATH.'/images');
define('STATICE_JS_PATH',STATICE_PATH.'/js');
优化项目index.php
<?php
require __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'common.php';
require DATA_PATH . '/data.php';
include TMPL_PATH_PUBLIC. '/header.php';
// var_dump($navArr);
?>
<!-- 主体 -->
<main>
<!-- 新闻列表 -->
<div class="news">
<h3>新闻列表</h3>
<div class="list">
<?php foreach($contentArr as $c): extract($c)?>
<a href="<?php echo $url?>"><?php echo ( mb_strlen($title) > 10 ? mb_substr($title,0,15).'...':$title)?></a>
<?php endforeach?>
</div>
</div>
<!-- 产品列表 -->
<div class="items">
<h3>产品列表</h3>
<div class="list">
<?php
foreach($productArr as $p): extract($p)
?>
<div class="item">
<img src="<?php echo $img?>" alt="<?php echo $title?>" />
<a href="<?=$url?>"><?= mb_strlen($content) > 8?mb_substr($content,0,10).'...':$content?></a>
</div>
<?php endforeach ?>
</div>
</div>
</main>
<!-- 页脚 -->
<?php
include TMPL_PATH_PUBLIC . '/footer.php';
?>
items.php
require __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'common.php';
require DATA_PATH . '/data.php';
include TMPL_PATH_PUBLIC. '/header.php';
//循环遍历产品列表
<div class="list">
<?php foreach($productArr as $p):
extract($p)
?>
<div class="item">
<img src="<?php echo $img?>" alt="<?php echo $title?>" />
<a href="<?=$url?>"><?= mb_strlen($content) > 8?mb_substr($content,0,10).'...':$content?></a>
</div>
<?php endforeach ?>
</div>
news.php
require __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'common.php';
require DATA_PATH . '/data.php';
include TMPL_PATH_PUBLIC. '/header.php';
//循环遍历新闻列表
<div class="list">
<?php foreach($contentArr as $c): extract($c)?>
<a href="<?=$url?>"><?= ( mb_strlen($title) > 10 ? mb_substr($title,0,15).'...':$title) ?></a>
<?php endforeach ?>
</div>