1. 变量作用域 2.优化web1项目,包括网站数据动态

编辑: admin 分类: 电脑知识 发布时间: 2023-06-14 来源:互联网
常量定义
  1. define('MY_DATE',date('Y-m-d h:i:s',time()));
  2. // 定义反斜线常量
  3. define('DS', DIRECTORY_SEPARATOR);
  4. //定义根目录常量
  5. define('ROOT_PATH', $_SERVER['DOCUMENT_ROOT'] .'/0410'.'/web1');
  6. //定义数据目录
  7. define('DATA_PATH', ROOT_PATH.'/Data');
  8. //定义模板目录
  9. define('TMPL_PATH',ROOT_PATH.'/template');
  10. // 定义公共目录
  11. define('TMPL_PATH_PUBLIC',TMPL_PATH.'/public');
  12. //定义静态资源目录
  13. define('STATICE_PATH',ROOT_PATH.'/static');
  14. define('STATICE_CSS_PATH',STATICE_PATH.'/css');
  15. define('STATICE_IMAGES_PATH',STATICE_PATH.'/images');
  16. define('STATICE_JS_PATH',STATICE_PATH.'/js');
优化项目index.php
  1. <?php
  2. require __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'common.php';
  3. require DATA_PATH . '/data.php';
  4. include TMPL_PATH_PUBLIC. '/header.php';
  5. // var_dump($navArr);
  6. ?>
  7. <!-- 主体 -->
  8. <main>
  9. <!-- 新闻列表 -->
  10. <div class="news">
  11. <h3>新闻列表</h3>
  12. <div class="list">
  13. <?php foreach($contentArr as $c): extract($c)?>
  14. <a href="<?php echo $url?>"><?php echo ( mb_strlen($title) > 10 ? mb_substr($title,0,15).'...':$title)?></a>
  15. <?php endforeach?>
  16. </div>
  17. </div>
  18. <!-- 产品列表 -->
  19. <div class="items">
  20. <h3>产品列表</h3>
  21. <div class="list">
  22. <?php
  23. foreach($productArr as $p): extract($p)
  24. ?>
  25. <div class="item">
  26. <img src="<?php echo $img?>" alt="<?php echo $title?>" />
  27. <a href="<?=$url?>"><?= mb_strlen($content) > 8?mb_substr($content,0,10).'...':$content?></a>
  28. </div>
  29. <?php endforeach ?>
  30. </div>
  31. </div>
  32. </main>
  33. <!-- 页脚 -->
  34. <?php
  35. include TMPL_PATH_PUBLIC . '/footer.php';
  36. ?>
items.php
  1. require __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'common.php';
  2. require DATA_PATH . '/data.php';
  3. include TMPL_PATH_PUBLIC. '/header.php';
  4. //循环遍历产品列表
  5. <div class="list">
  6. <?php foreach($productArr as $p):
  7. extract($p)
  8. ?>
  9. <div class="item">
  10. <img src="<?php echo $img?>" alt="<?php echo $title?>" />
  11. <a href="<?=$url?>"><?= mb_strlen($content) > 8?mb_substr($content,0,10).'...':$content?></a>
  12. </div>
  13. <?php endforeach ?>
  14. </div>
news.php
  1. require __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'common.php';
  2. require DATA_PATH . '/data.php';
  3. include TMPL_PATH_PUBLIC. '/header.php';
  4. //循环遍历新闻列表
  5. <div class="list">
  6. <?php foreach($contentArr as $c): extract($c)?>
  7. <a href="<?=$url?>"><?= ( mb_strlen($title) > 10 ? mb_substr($title,0,15).'...':$title) ?></a>
  8. <?php endforeach ?>
  9. </div>
【转自:韩国lg机房 http://www.558idc.com/lg.html欢迎留下您的宝贵建议】