The DoYouHaoBaby PHP Framework中文开发文档手册
Copyright(c) DoYouHaoBaby.NET All Rights Reserved.
[ 读取任务列表 ]

在上一节,我们学会了如何添加一个任务,我们到底添加了什么任务呢,我们可以将它读取出来。

这一节,我们将把我们添加的任务从数据库中读取出来。

任务列表,我们直接在首页进行展示,位于IndexController.class.php中index中:

  1. public function index(){   
  2.            
  3.         $oTaskModelSelect = TaskModel::F();   
  4.   
  5.         $nTotalRecord = $oTaskModelSelect  
  6.                         ->all()   
  7.                         ->getCount( );   
  8.   
  9.         // 前台日志列表分页数量   
  10.         $nEverynum = 5;   
  11.   
  12.         // 使用分页类   
  13.         $oPage = Page::RUN( $nTotalRecord,$nEverynum, Safe::getGpc( G::C('PAGE_VAR_NAME'),'G' ) );   
  14.         $sPageNavbar = $oPage->P( 'pagination' );   
  15.   
  16.         // 获取数据列表   
  17.         $arrTaskLists = $oTaskModelSelect  
  18.                        ->all()   
  19.                        ->order( 'task_id DESC' )   
  20.                        ->limit( $oPage->returnPageStart( ), $nEverynum )   
  21.                        ->query();   
  22.   
  23.         $this->assign( 'arrTaskLists',$arrTaskLists );   
  24.         $this->assign( 'sPageNavbar',$sPageNavbar );   
  25.         $this->display( );   
  26.     }  


然后 ,我们在index_index.html将数据库的数据展示出来:
  1. <include file="public+header">   
  2.   
  3.     <div id="content_wrapper">   
  4.       <div id="content">   
  5.         <div class="content_section divider">   
  6.           <h2>欢迎你来到我们的演示庭</h2>   
  7.           <p>我们我们将会带领大家开发一个简单的wedoit 在线任务管理器程序。 </p>   
  8.           {if $GLOBALS['___login___']===false}<p>你可以在这里注册一个用户,<a href="{:G::U( 'user/register' )}">注册</a> | <a href="{:G::U( 'user/login' )}">登录</a></p>   
  9.           {d*else}登录用户 | <a href="{:G::U( 'index/change_password?id='.$GLOBALS['___login___']['user_id'] )}">{$GLOBALS['___login___']['user_name']}</a> <a href="{:G::U( 'user/logout' )}">注销</a> | <a href="{:G::U( 'index/add' )}">添加任务</a> {/if}   
  10.         </div>   
  11.         <table border="1" cellpadding="5" cellspacing="0">   
  12.         <thead>   
  13.         <tr>   
  14.           <th>任务ID</th>   
  15.           <th>任务主题</th>   
  16.           <th>任务描述</th>   
  17.           <th>创建时间</th>   
  18.           <th>更新时间</th>   
  19.           <th>是否完成</th>   
  20.           <th>用户</th>   
  21.            {if $GLOBALS['___login___']!==false}<th>操作</th>{/if}   
  22.         </tr>   
  23.         </thead>   
  24.         <tbody>   
  25.         <foreach for=arrTaskLists value=arrTaskList>   
  26.         <tr>   
  27.           <th>{$arrTaskList['task_id']}</th>   
  28.           <th>{$arrTaskList['task_subject']}</th>   
  29.           <th>{$arrTaskList['task_description']}</th>   
  30.           <th>{$arrTaskList['create_dateline']|date='Y-m-d H:i:s',**}</th>   
  31.           <th>{$arrTaskList['update_dateline']|date='Y-m-d H:i:s',**}</th>   
  32.           <th>{if $arrTaskList['task_is_completed']}是{d*else}否{/if}</th>   
  33.           <th>{$arrTaskList:user:user_name}</th>   
  34.            {if $GLOBALS['___login___']!==false}<th><a href="{:G::U( 'index/update_task?id='.$arrTaskList['task_id'] )}">编辑</a> | <a href="{:G::U( 'index/delete_task?id='.$arrTaskList['task_id'] )}">删除</a> | {if $arrTaskList['task_is_completed']==1}已完成{d*else}<a href="{:G::U( 'index/do_task?id='.$arrTaskList['task_id'] )}">做任务</a>{/if}</th>{/if}   
  35.         </tr>   
  36.         </foreach>   
  37.         </tbody>   
  38.         </table>   
  39.   
  40.         {$sPageNavbar}   
  41.   
  42.       </div>   
  43.       <include file="public+sidebar">   
  44.   
  45. <include file="public+footer">  


说明:模板中的代码很简单,就是一个简单的foreach循环,就将数据库中的记录给读取出来了。

效果如下:


根据逻辑代码,你可以看出,我们系统为你封装了分页类,你直接使用即可,是不是很简单啦。

To be continue!