首頁 >後端開發 >php教程 >如何从零开始教女同学进行PHP开发:写需求文档_PHP教程

如何从零开始教女同学进行PHP开发:写需求文档_PHP教程

WBOY
WBOY原創
2016-07-13 17:19:02906瀏覽

背景:远在北京的高中女同学让我帮忙当她的实训“技术顾问”,实训要求个人独立开发一个web项目,她选择的开发语言是php。其实我又当了一次标题党,她虽然以前从来没用过PHP,但是却有一点点html、css、javascript基础据说已经忘光了),有用过C和java写过东西。

项目描述:

题目——资源预定管理系统

功能需求——

1. 针对企事业单位开发一个资源预定管理系统

2. 针对不同类别的资源,例如会议室、汽车、仪器设备等,向员工提供预约使用的功能

3. 员工登录系统后,可以查看指定的资源当前的预定情况,可以预定指定时间段内空闲的资源。

4. 不同的资源需要根据情况设置不同开放时间,例如每天的8:00到18:00,用于智能在开发时间内进行预定

5. 不同的资源可以预定的最小时间单位是不同的,例如会议室按分钟进行预定,最短15分钟,汽车按小时预定,最短2个小时。

6. 系统遵循先到先得的原则进行预定。

7. 用户预定后,尚未使用前可以取消,取消后,其它用户可以继续预定

第一步:写需求文档

计算机专业的同学一般都上过软件工程这门课,自然知道做需求的重要性。就算没上过,有过工作经验的同志们也应该看过别人写的需求文档。如果把一个项目的完成比作造房子,那么需求就好比建筑设计图,如果设计的不好,那么造出来的房子也不会好看。虽然软件开发比建筑有更大的灵活性起码房子不能动不动就回滚代码,撤销更改),但是需求要是做得不全面不严格,往往会极大地增加不必要的工作量和降低工作效率。

你想想,今天告诉你这样一个需求,你代码写了一半,过几天告诉你需求改了,之前的代码都没用了,你什么感觉?虽然需求变更是常有的事,但是一旦需求发生失控,对项目的影响往往是灾难性的。

幸好妹子之前做桌面软件课程设计的时候写过需求文档,不然要从头开始学怎么做需求还是一件蛮麻烦的事情。但如果刚入门的童鞋嫌麻烦不做需求是大大的不妥,且不论进入正式工作后要接触更为严格严谨的需求文档,哪怕只是应付学校里的课程设计,在软件规模足够大的情况下,做需求用一天的时间,起码可以使开发的时间缩短一个星期。

第二步:登录页面的举例

妹子写需求文档去了,那我也不能闲着。因为我之前只是稍微看过php的相关资料,并没有用过php写过一行代码,为了走在妹子前面,必须要提前学习妹子要用的东西。由于这个课程设计的项目有登录的功能,所以我打算用这个页面作为介绍php的第一个例子,并且往后还会就登录功能整个流程进行更加详尽的说明。

首先,我们看一个最简单的html登录页面,上代码!

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span class="tag-name">html</span><span class="tag">></span><span> </span></span></span></li>
<li>
<span> </span><span class="tag"><span class="tag-name">head</span><span class="tag">></span><span> </span></span>
</li>
<li class="alt">
<span> </span><span class="tag"><span class="tag-name">meta</span><span> </span><span class="attribute">charset</span><span>=</span><span class="attribute-value">"gbk"</span><span class="tag">></span><span> </span></span>
</li>
<li>
<span> </span><span class="tag"><span class="tag-name">title</span><span class="tag">></span><span>用户登录界面</span><span class="tag"></span><span class="tag-name">title</span><span class="tag">></span><span> </span></span>
</li>
<li class="alt">
<span> </span><span class="tag"></span><span class="tag-name">head</span><span class="tag">></span><span> </span>
</li>
<li>
<span> </span><span class="tag"><span class="tag-name">body</span><span class="tag">></span><span> </span></span>
</li>
<li class="alt">
<span> </span><span class="tag"><span class="tag-name">form</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"login"</span><span> </span><span class="attribute">action</span><span>=</span><span class="attribute-value">"Controller.php"</span><span> </span><span class="attribute">method</span><span>=</span><span class="attribute-value">"post"</span><span> </span><span class="tag">></span><span>     </span></span>
</li>
<li>
<span> </span><span class="tag"><span class="tag-name">td</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"tbl"</span><span class="tag">></span><span>用户名:</span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text"</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"user_id"</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span>      </span></span></span></span>
</li>
<li class="alt">
<span>     </span><span class="tag"><span class="tag-name">td</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"tbl"</span><span class="tag">></span><span>密码:</span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text"</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"user_password"</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></span></span>
</li>
<li>
<span>     </span><span class="tag"><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"submit"</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">"登入系统"</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></span>
</li>
<li class="alt">
<span> </span><span class="tag"></span><span class="tag-name">form</span><span class="tag">></span><span> </span>
</li>
<li>
<span> </span><span class="tag"></span><span class="tag-name">body</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span class="tag"></span><span class="tag-name">html</span><span class="tag">></span><span> </span>
</li>
</ol>

为了让大家不当极致的伸手党,我就不把页面截图上来了,大家自己复制代码用浏览器看看效果。为什么我要给妹子写这几行代码呢?主要是想让妹子重新熟悉一下html代码长什么样子,而且是为了下面让妹子知道php与html为什么混合在一起做铺垫。过了这么一会儿,大家应该已经看过上面那些代码的显示效果了吧。既然这样,请看下面加入php后的代码:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"></span><span class="tag-name">php</span><span>         //php代码部分开始  </span></span></li>
<li>
<span>echo "</span><span class="tag"><span class="tag-name">html</span><span class="tag">></span><span>";  </span></span>
</li>
<li class="alt">
<span>echo "</span><span class="tag"><span class="tag-name">head</span><span class="tag">></span><span>";  </span></span>
</li>
<li>
<span>echo "</span><span class="tag"><span class="tag-name">meta</span><span> </span><span class="attribute">charset</span><span>=\"gbk\"</span><span class="tag">></span><span>";  </span></span>
</li>
<li class="alt">
<span>echo "</span><span class="tag"><span class="tag-name">title</span><span class="tag">></span><span>用户登录界面</span><span class="tag"></span><span class="tag-name">title</span><span class="tag">></span><span>";  </span></span>
</li>
<li>
<span class="tag">?></span><span class="comments"><!--  php代码部分结束--></span><span> </span>
</li>
<li class="alt">
<span class="tag"></span><span class="tag-name">head</span><span class="tag">></span><span> </span>
</li>
<li><span class="tag"><span class="tag-name">body</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span class="tag"><span class="tag-name">form</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"login"</span><span> </span><span class="attribute">action</span><span>=</span><span class="attribute-value">"Controller.php"</span><span> </span><span class="attribute">method</span><span>=</span><span class="attribute-value">"post"</span><span> </span><span class="tag">></span><span> </span></span></li>
<li>
<span>     </span><span class="tag"><span class="tag-name">td</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"tbl"</span><span class="tag">></span><span>用户名:</span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text"</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"user_id"</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span>      </span></span></span></span>
</li>
<li class="alt">
<span>     </span><span class="tag"><span class="tag-name">td</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"tbl"</span><span class="tag">></span><span>密码:</span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text"</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"user_password"</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></span></span>
</li>
<li>
<span class="tag"></span><span class="tag-name">php</span><span>      </span>
</li>
<li class="alt">
<span>echo "</span><span class="tag"><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=\"submit\" </span><span class="attribute">value</span><span>=\"登入系统\"</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span>"  </span></span></span>
</li>
<li>
<span class="tag">?></span><span> </span>
</li>
<li class="alt">
<span class="tag"></span><span class="tag-name">form</span><span class="tag">></span><span> </span>
</li>
<li>
<span class="tag"></span><span class="tag-name">body</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span class="tag"></span><span class="tag-name">html</span><span class="tag">></span><span> </span>
</li>
</ol>

这段代码主要让妹子了解这么几点:1)php代码要用标签进行标识2)如何使用echo语句进行输出html代码,另外关于要用对""中的"(双引号)用\转义符)进行转义。3)php代码是如何跟html代码进行混合的。

PS:完事开头难,第一篇文章就先写这么多。起点定的太高反而不好,容易把初学者搞迷糊了。多看作为例子的代码,自己动手改一改,写一写,感受一下。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/601050.htmlTechArticle背景:远在北京的高中女同学让我帮忙当她的实训技术顾问,实训要求个人独立开发一个web项目,她选择的开发语言是php。其实我又当了一...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn