1. 程式人生 > >4)在url中加上a分發參數,用來選哪一個函數

4)在url中加上a分發參數,用來選哪一個函數

doc mpat str rds utf8 class control cnblogs tab

文件關系目錄展示:

    技術分享

然後代碼改動部分展示:

    zixun.controller.class.php

      技術分享

 1 <?php
 2     //header(‘Content-type:text/html;charset=utf8‘);
 3     
 4     /**
 5      * Created by PhpStorm.
 6      * User: Interact
 7      * Date: 2017/8/19
 8      * Time: 18:37
 9      */
10     class zixun {
11         /**
12 * 方法show() 13 * @return string aaa 14 * 原來的靜態方法改成非靜態 15 */ 16 public function show() { 17 // require ‘zixunModel.class.php‘; 18 // $zixunModel=new zixunModel(); 19 require ./Factory.class.php; 20 21 $zixunModel = Factory::M(
zixunModel); 22 23 $records = $zixunModel->getall(); 24 25 // var_dump($records); 26 require html/show.html; 27 // return ‘12233‘; 28 } 29 public function delete(){ 30 echo 真的刪除啦,你別後悔!!!; 31
} 32 33 } 34 35 36 37 38

然後我的index.php代碼展示:

        技術分享

 1 <?php
 2     /**
 3      * Created by PhpStorm.
 4      * User: Interact
 5      * Date: 2017/8/19
 6      * Time: 22:02
 7      */
 8     //確定分發參數
 9     //動作
10     $default_action=show;
11     $a=isset($_GET[a])?$_GET[a]:$default_action;
12 require zixun.controller.class.php;
13 $controller=new zixun();
14 $action_name=$a;
15 $controller->$action_name();

我的html代碼展示:

      技術分享

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="utf-8"><!-- 編碼格式是 utf-8 -->
 5     <meta http-equiv="X-UA-Compatible" content="IE=edge"><!-- 使用最新式 ie 內核渲染國內某些 所謂的 雙核瀏覽器 或者是 直接 使用webkit去渲染-->
 6     <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
 7     <!-- 視口屬性沒有設置 禁用 用戶縮放, 如果有需求可以添加-->
 8     <!-- 上述3個meta標簽*必須*放在最前面,任何其他內容都*必須*跟隨其後! -->
 9     <title>bootstrap的模板頁</title>
10     <!-- Bootstrap -->
11 
12 </head>
13 <body>
14 <table>
15     <tr>
16        <th>ID&nbsp&nbsp&nbsp</th>
17         <th>名字&nbsp&nbsp&nbsp</th>
18         <th>分類&nbsp&nbsp&nbsp</th>
19         <th>作者&nbsp&nbsp&nbsp</th>
20         <th>更新時間&nbsp&nbsp</th>
21         <th>瀏覽次數&nbsp&nbsp</th>
22         <th>發布狀態&nbsp&nbsp</th>
23     </tr>
24     <?php foreach($records as $row) : ?>
25     <tr>
26         <th><?php echo $row[ZX_id]; ?></th>
27         <th><?php echo $row[ZX_name]; ?></th>
28         <th><?php echo $row[ZX_fenlei]; ?></th>
29         <th><?php echo $row[ZX_zuozhe]; ?></th>
30         <th><?php echo $row[gengxin_time]; ?></th>
31         <th><?php echo $row[liulan_cishu]; ?></th>
32         <th><?php echo $row[fabu_zhuangtai]; ?></th>
33         <th><a href="index.php?a=delete">刪除</a></th>
34     </tr>
35     <?php endforeach ?>
36 </table>
37 </body>
38 </html>

結果展示:
      技術分享

4)在url中加上a分發參數,用來選哪一個函數