4)在url中加上a分发参数,用来选哪一个函数

文件关系目录展示:

    

 

 

然后代码改动部分展示:

    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>

结果展示:
      

 

posted @ 2017-08-20 10:13  小油菜1  阅读(197)  评论(0编辑  收藏  举报