最近闲来无事,自己尝试通过thinkphp3.1.3框架开发一套自己的OA系统,目前已完成了人力资源管理部分的内容,遇到并解决了几个问题。

1.由于刚开始不太熟悉thinkphp的框架,花费了一些功夫去了解。重点阅读了开发手册:http://doc.thinkphp.cn/manual/preface.html

2.问题:HTML 布局  规划布局为 header(头部)+side(左侧导航)+content(内容)的布局。

  学习点:div 布局

      1)position:absolute :

      2)top:30px;left:30px; :相对于整个页面距离顶部和左边的距离

      3)height:150px;width:1900px;:div 的高度和宽度

#header{position:absolute;height:150px;width:1900px;color:#fff;background:#666;line-height:50px;z-index:;top:0px;left:0px}
#content{position:absolute;width:1895px;color:#fff;float:right;margin-left:-170px;margin-top:0px;z-index:;top:145px;left:175px}
#content_inner{position:absolute;width:1725px;height:665px;background:#333300;top:15px;left:170px}
#side{position:absolute;width:265px;height:760px;color:#fff;background:#FFFFFF;float:left;margin-top:0px;z-index:;;top:160px;left:0px}
#side_inner{position:absolute;width:;heigth:550px;top:0px}
#footer{position:absolute;height:50px;color:#fff;background:#666;margin-top:10px;z-index:}

  thinkphp模板包含整合:<include file="./Tpl/Home/index/index_layout.html"/>  注:有使用分组Home,Admin

    问题:模板包含导致读取的CSS,JS无效的问题:<script src="/app/public/js/jquery-1.11.2.min.js" type="text/javascript"></script>    使用这样的地址方式才有效

3.问题:模板读取信息ajax至指定控制器方法并返回json数据集,并对json数据集进行遍历输出。期间遇到编码的问题,显示中文为乱码,需要调整全部的编码方式为UTF-8,首先调整编辑器的编码方式,然后是thinkphp的编码方式,以及数据库的编码方式。

  PersonnelmattersAction.class.php  的 handlename()

     //getmember ajax name
public function handlename()
{
if( IS_POST )
{
$Data = M('Personnelmatters');
$cate = $_POST['name'];
//$cate = iconv("UTF-8","GB2312//TRANSLIT",$cate);
$field ="id,aid,department,station,entry_time,name,privatephone,companyphone,idnumber,education,maritalstatus,drivinglicense,email,job";
$result = $Data->field($field)->where(array('name'=> $cate))->select();
//$this->ajaxReturn($result,"OK",1);
echo json_encode($result,true);
}else
{
echo json_encode("",true);
}
}

  PersonnelmattersModel.class.php

<?php

    class PersonnelmattersModel extends Model{
//指定数据库
protected $dbName = 'yloa'; //定义模型字段
protected $fields = array(
'id',
'aid',
'department',
'station',
'entry_time',
'name',
'privatephone',
'companyphone',
'idnumber',
'education',
'maritalstatus',
'drivinglicense',
'email',
'job',
'_pk' => 'id',
'_autoinc' => true
); // 定义自动验证
protected $_validate = array(
array('aid','require','工号必须'),
array('department','require','部门必须'),
array('station','require','岗位必须'),
array('entry_time','require','入职时间必须'),
array('name','require','工号必须'),
array('privatephone','require','个人电话必须'),
array('idnumber','require','身份证必须'),
array('education','require','学历必须'),
array('maritalstatus','require','婚否必须'),
array('drivinglicense','require','是否有驾照必须'),
array('email','require','邮箱必须'),
array('job','require','是否在职必须'),
); }

  getmember.html

<select id="name" style="height:30px;width:75px">
<volist name="search" id="vo">
<option value="{$vo.name}">{$vo.name}</option>
</volist>
</select>
     $(function(){
var ajaxUrl = "/app/index.php/Personnelmatters/handlename";
$("#name").change(function(){
var name = $("#name").val();
$.post(ajaxUrl,{"name":name},function(json){
printPersonnelmatters(json);
},'json');
});
})
  //员工资料展示
function printPersonnelmatters(json)
{
if(json == null || json == undefined || json == '')
{
$("#result").html("返回值为空!");
}
else
{
var len = json.length;
var tableStr ="<table class='imagetable'>";
tableStr = tableStr + "<tr><th>序号</th><th>工号</th><th>部门</th><th>职务</th><th>入职时间</th><th>姓名</th><th>私人电话</th><th>公司电话</th><th>身份证</th><th>学历</th><th>婚否</th><th>是否有驾照</th><th>邮箱</th><th>是否在职</th><th>操作</th></tr>";
for(var i=0;i<len;i++)
{
tableStr = tableStr + "<tr><td id='myid'>"+ json[i].id +"</td>"
+"<td>"+ json[i].aid + "</td>"
+"<td>"+ json[i].department + "</td>"
+"<td>"+ json[i].station + "</td>"
+"<td>"+ json[i].entry_time + "</td>"
+"<td>"+ json[i].name + "</td>"
+"<td>"+ json[i].privatephone + "</td>"
+"<td>"+ json[i].companyphone + "</td>"
+"<td>"+ json[i].idnumber + "</td>"
+"<td>"+ json[i].education + "</td>"
+"<td>"+ json[i].maritalstatus + "</td>"
+"<td>"+ json[i].drivinglicense + "</td>"
+"<td>"+ json[i].email + "</td>"
+"<td>"+ json[i].job + "</td>"
+"<td>"+ "<nobr><input type='button' id='edit' value='编辑' onclick='javascript:edit_id("+json[i].id+");' /><input type='button' id='delete' value='删除' onclick='javascript:delete_id("+json[i].id+");' /></nobr>"+ "</td></tr>";
}
tableStr = tableStr + "</table>";
$("#result").html(tableStr);
}
}

  问题:获取指定行id。直接在展示方法中传值

4.问题:thinkphp数据分页,thinkphp有自带的数据分页类。

  PersonnelmattersAction.class.php  的 getmember()

         //获取职员信息
public function getmember(){
$Data = M('Personnelmatters');
import('ORG.Util.Page');// 导入分页类
$count = $Data->count();// 查询满足要求的总记录数
$lastpage = floor(($count/10)+1);
$Page = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
$show = $Page->show();// 分页显示输出
// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
$list = $Data->limit($Page->firstRow.','.$Page->listRows)->select();
$this->assign('list',$list);// 赋值数据集
$this->assign('page',$show);// 赋值分页输出
$this->assign('lastpage',$lastpage);
//echo $Data->getLastSql();
$this->search = $Data ->select();
$this->display();
}

  getmember.html

<div id="result">
<table class='imagetable'>
<tr>
<th>序号</th>
<th>工号</th>
<th>部门</th>
<th>职务</th>
<th>入职时间</th>
<th>姓名</th>
<th>私人电话</th>
<th>公司电话</th>
<th>身份证</th>
<th>学历</th>
<th>婚否</th>
<th>是否有驾照</th>
<th>邮箱</th>
<th>是否在职</th>
<th>操作</th>
</tr>
<volist name="list" id="vo" key="k">
<tr align="center">
<td>{$vo.id}</td>
<td>{$vo.aid}</td>
<td>{$vo.department}</td>
<td>{$vo.station}</td>
<td>{$vo.entry_time}</td>
<td>{$vo.name}</td>
<td>{$vo.privatephone}</td>
<td>{$vo.companyphone}</td>
<td>{$vo.idnumber}</td>
<td>{$vo.education}</td>
<td>{$vo.maritalstatus}</td>
<td>{$vo.drivinglicense}</td>
<td>{$vo.email}</td>
<td>{$vo.job}</td>
<td>
<nobr><input type="button" id="edit" value="编辑" onclick="javascript:edit_id({$vo.id});" /><input type="button" id="delete" value="删除" onclick="javascript:delete_id({$vo.id});" /></nobr>
</td>
</tr>
</volist>
</table>
<div style="position:absolute;width:1425px;heigth:30px;top:500px;" align="center">
<hr>{$page}&nbsp;<a href="/app/index.php/Personnelmatters/getmember/p/1">首页</a>&nbsp;<a href="/app/index.php/Personnelmatters/getmember/p/{$lastpage}">末页</a><hr>
</div>

最新文章

  1. 全栈开发必备的10款 Sublime Text 插件
  2. leetcode 236. Lowest Common Ancestor of a Binary Tree
  3. json时间格式化问题
  4. bat命令
  5. piap.excel 微软 时间戳转换mssql sql server文件时间戳转换unix 导入mysql
  6. 基于SWFUpload的angular上传组件
  7. MVVM模式的一个小例子
  8. 3.4.2内核下的I2C驱动
  9. mongodb 学习初探
  10. C语言中结构体參数变量的传递
  11. makefile知识点归纳的
  12. struts2.1.6教程五、拦截器
  13. Go语言中函数的实现
  14. 继webpack后又一打包神器Parcel
  15. js 模拟超级大LE透中头奖 统计中头奖需要购买的彩票次数以及购买总金额
  16. linux目录文件及系统启动知识
  17. BZOJ3456 城市规划 【多项式求ln】
  18. Git的常见基础操作命令
  19. angular的组件通信
  20. js 继承的方式

热门文章

  1. c# winform读取xml创建菜单
  2. USACO chapter1
  3. 怎样注册uber司机 如何注册uber司机 最新详细攻略
  4. Java图形化界面设计——容器(JFrame)
  5. 【从零学习Python】Ubuntu14.10下Python开发环境配置
  6. HTTP&#160;错误
  7. JavaScript 深入学习及常用工具方法整理 ---- 01.浮点数
  8. 我们在 web 应用开发过程中经常遇到输出某种编码的字 符, 如 iso8859-1 等, 如何输出一个某种编码的字符串?
  9. UVa1586 Molar mass
  10. php mysql实现栏目分类递归