The DoYouHaoBaby PHP Framework中文开发文档手册
Copyright(c) DoYouHaoBaby.NET All Rights Reserved.
Copyright(c) DoYouHaoBaby.NET All Rights Reserved.
[ 编辑任务 ]
有时候,我们需要临时更改我们的任务,这个时候我们需要编辑任务。
编辑任务很简单,就是一个简单的更新操作。
编辑界面的代码,获取编辑的任务,位于IndexController.class.php的update_task:
- public function update_task(){
- // 判断是否已经登录
- if( $GLOBALS['___login___']===false )
- $this->E( G::L( '你没有登录' ) );
- $nTaskId= intval(Safe::getGpc( 'id' ));
- if( !empty($nTaskId) ){
- $oTask = TaskModel::F( 'task_id=?',$nTaskId )
- ->query();
- if( empty($oTask['task_id']) ){
- $this->E( '任务不存在' );
- }
- else{
- if( $GLOBALS['___login___']['user_id']!=$oTask['user_id'] ){
- $this->E( '你不能编辑别人的任务' );
- }
- else{
- $this->assign( 'oTask',$oTask );
- $this->display( );
- }
- }
- }
- else
- $this->E( '你没有选择任务' );
- }
我们在模板index_update_task.html中写下如下的代码:
- <include file="public_header">
- <div id="content_wrapper">
- <div id="content">
- <form name="form_task" id="form_task" action="{:G::U('index/update_the_task')}"
- method="post">
- <fieldset>
- <p>
- <label for="task_subject">任务主题</label> <br/>
- <input type="text" name="task_subject" id="task_subject" value="{$oTask['task_subject']}" />
- </p>
- <p>
- <label for="task_description">任务内容</label><br/>
- <textarea name="task_description" id="task_description">{$oTask['task_description']}
- </textarea>
- </p>
- <p>
- <input type="submit" name="Submit" value="更新任务" />
- <input type="hidden" name="id" value="{$oTask['task_id']}"/>
- </p>
- </fieldset>
- </form>
- <p>你可以返回首页,<a href="{:G::U( 'index/index' )}">返回首页</a> </p>
- </div>
- <include file="public_sidebar">
- <include file="public_footer">
访问首页的任务“编辑”,地址为http://localhost/wedoit/index.php/index/update_task/id/1。
你可以看到如下的界面:

修改了任务,然后我们需要保存,位于IndexController.class.php中的update_the_task:
- public function update_the_task(){
- // 判断是否已经登录
- if( $GLOBALS['___login___']===false )
- $this->E( G::L( '你没有登录' ) );
- $nId = intval( Safe::getGpc( 'id' ) );
- $oTask = TaskModel::F( 'task_id=?',$nId )
- ->query();
- if( empty($oTask['task_id']) ){
- $this->E( '任务不存在' );
- }
- else{
- if( $GLOBALS['___login___']['user_id']!=$oTask['user_id'] ){
- $this->E( '你不能编辑别人的任务' );
- }
- else{
- $oTask->save( 0,'update' );
- if( $oTask->isError() )
- $this->E( $oTask->getErrorMessage() );
- $this->S( '任务更新成功' );
- }
- }
- }
}
然后,你保存,访问首页的效果如下。
如图2:
To be continue!
