PHP自动生成后台导航网址的最佳方法

 1 <?php
2 $linkArr = array(
3 'index.php' => '汇总首页',
4 'List.php' => '列表',
5 'Detail.php' => '详细',
6 'http://qzone.qq.com/' => 'QQ空间',
7 'http://www.jbxue.com'=> '脚本学堂首页', 8 'login.php?act=logout' => '安全退出',
9 );
10 ?>
11
12 <?php
13 foreach($linkArr as $k => $v)
14 {
15 if(basename($k) == basename($_SERVER['PHP_SELF']))
16 {
17 $class = ' class="curr-ac"';
18 if(!defined('PAGE_TITLE')) define('PAGE_TITLE', $v);
19 } else {
20 $class = '';
21 }
22 echo '<input type="button" value="'.$v.'" '.$class.' name="ac-button" _url="'.$k.'" onclick="Daohang(this)" />';
23 }
24 ?>
25 <script>
26 var PAGE_TITLE = <?php echo json_encode(defined('PAGE_TITLE') ? PAGE_TITLE : '');?>;
27 if(PAGE_TITLE) document.title = PAGE_TITLE + ' ' + document.title;
28 function Daohang(obj)
29 {
30 var url = obj.getAttribute('_url');
31 if(/^https?://.+/i.test(url))
32 {
33 window.open(url,'');
34 } else {
35 window.location = url;
36 }
37 }
38 </script>