设为首页 加入收藏

TOP

编写自己的PHP MVC框架笔记(五)
2017-10-10 11:58:31 】 浏览:2091
Tags:编写 自己 PHP MVC 框架 笔记

在 views 目录下新建 header.php 和 footer.php 两个页头页脚模板,内容如下。

header.php,内容:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><?php echo $title ?></title>
    <style>
        .item {
            width:400px;
        }
 
        input {
            color:#222222;
            font-family:georgia,times;
            font-size:24px;
            font-weight:normal;
            line-height:1.2em;
            color:black;
        }
 
        a {
            color:blue;
            font-family:georgia,times;
            font-size:20px;
            font-weight:normal;
            line-height:1.2em;
            text-decoration:none;
         }
 
        a:hover {
            text-decoration:underline;
        }
 
        h1 {
            color:#000000;
            font-size:41px;
            letter-spacing:-2px;
            line-height:1em;
            font-family:helvetica,arial,sans-serif;
            border-bottom:1px dotted #cccccc;
        }
 
        h2 {
            color:#000000;
            font-size:34px;
            letter-spacing:-2px;
            line-height:1em;
            font-family:helvetica,arial,sans-serif;
        }
    </style>
</head>
<body>
    <h1><?php echo $title ?></h1>
footer.php,内容:

</body>
</html>

然后,在 views/item 创建以下几个视图文件。

index.php,浏览数据库内 item 表的所有记录,内容:

<form action="<?php echo APP_URL ?>/item/add" method="post">
    <input type="text" value="点击添加" onclick="this.value=''" name="value">
    <input type="submit" value="添加">
</form>
<br/><br/>
 
<?php $number = 0?>
 
<?php foreach ($items as $item): ?>
    <a class="big" href="<?php echo APP_URL ?>/item/view/<?php echo $item['id'] ?>" title="点击修改">
        <span class="item">
            <?php echo ++$number ?>
            <?php echo $item['item_name'] ?>
        </span>
    </a>
    ----
    <a class="big" href="<?php echo APP_URL ?>/item/delete/<?php echo $item['id']?>">删除</a>
<br/>
<?php endforeach ?>

add.php,添加记录,内容:

<a class="big" href="<?php echo APP_URL ?>/item/index">成功添加<?php echo $count ?>条记录,点击返回</a>

view.php,查看单条记录,内容:

<form action="<?php echo APP_URL ?>/item/update" method="post">
    <input type="text" name="value" value="<?php echo $item['item_name'] ?>">
    <input type="hidden" name="id" value="<?php echo $item['id'] ?>">
    <input type="submit" value="修改">
</form>
 
<a class="big" href="<?php echo APP_URL ?>/item/index">返回</a>

update.php,更改记录,内容:

<a class="big" href="<?php echo APP_URL ?>/item/index">成功修改<?php echo $count ?>项,点击返回</a>

delete.php,删除记录,内容:

<a href="<?php echo APP_URL ?>/item/index">成功删除<?php echo $count ?>项,点击返回</a>

4.5应用测试

这样,在浏览器中访问 myphp程序:http://localhost/myphp/item/index/,就可以看到效果了。

首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇【夯实PHP系列】PHP正则表达式 下一篇PHP中抽象类,接口定义

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目