The DoYouHaoBaby PHP Framework中文开发文档手册
Copyright(c) DoYouHaoBaby.NET All Rights Reserved.
Copyright(c) DoYouHaoBaby.NET All Rights Reserved.
[ 读取任务列表 ]
在上一节,我们学会了如何添加一个任务,我们到底添加了什么任务呢,我们可以将它读取出来。
这一节,我们将把我们添加的任务从数据库中读取出来。
任务列表,我们直接在首页进行展示,位于IndexController.class.php中index中:
- public function index(){
- $oTaskModelSelect = TaskModel::F();
- $nTotalRecord = $oTaskModelSelect
- ->all()
- ->getCount( );
- // 前台日志列表分页数量
- $nEverynum = 5;
- // 使用分页类
- $oPage = Page::RUN( $nTotalRecord,$nEverynum, Safe::getGpc( G::C('PAGE_VAR_NAME'),'G' ) );
- $sPageNavbar = $oPage->P( 'pagination' );
- // 获取数据列表
- $arrTaskLists = $oTaskModelSelect
- ->all()
- ->order( 'task_id DESC' )
- ->limit( $oPage->returnPageStart( ), $nEverynum )
- ->query();
- $this->assign( 'arrTaskLists',$arrTaskLists );
- $this->assign( 'sPageNavbar',$sPageNavbar );
- $this->display( );
- }
然后 ,我们在index_index.html将数据库的数据展示出来:
- <include file="public+header">
- <div id="content_wrapper">
- <div id="content">
- <div class="content_section divider">
- <h2>欢迎你来到我们的演示庭</h2>
- <p>我们我们将会带领大家开发一个简单的wedoit 在线任务管理器程序。 </p>
- {if $GLOBALS['___login___']===false}<p>你可以在这里注册一个用户,<a href="{:G::U( 'user/register' )}">注册</a> | <a href="{:G::U( 'user/login' )}">登录</a></p>
- {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}
- </div>
- <table border="1" cellpadding="5" cellspacing="0">
- <thead>
- <tr>
- <th>任务ID</th>
- <th>任务主题</th>
- <th>任务描述</th>
- <th>创建时间</th>
- <th>更新时间</th>
- <th>是否完成</th>
- <th>用户</th>
- {if $GLOBALS['___login___']!==false}<th>操作</th>{/if}
- </tr>
- </thead>
- <tbody>
- <foreach for=arrTaskLists value=arrTaskList>
- <tr>
- <th>{$arrTaskList['task_id']}</th>
- <th>{$arrTaskList['task_subject']}</th>
- <th>{$arrTaskList['task_description']}</th>
- <th>{$arrTaskList['create_dateline']|date='Y-m-d H:i:s',**}</th>
- <th>{$arrTaskList['update_dateline']|date='Y-m-d H:i:s',**}</th>
- <th>{if $arrTaskList['task_is_completed']}是{d*else}否{/if}</th>
- <th>{$arrTaskList:user:user_name}</th>
- {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}
- </tr>
- </foreach>
- </tbody>
- </table>
- {$sPageNavbar}
- </div>
- <include file="public+sidebar">
- <include file="public+footer">
说明:模板中的代码很简单,就是一个简单的foreach循环,就将数据库中的记录给读取出来了。
效果如下:

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