最近要帮我哥的公司做一个企业网站,再加以我叔公司的网站到现在还是半成品就挂到网上了,心中老是过意不去,但是自己都去好好解决一下,最近也有空了,准备花上一周左右的时间,把这两个企业网站做掉。
做完这二个网站后,自己也准备做一个网站自己用了,时间过得真快,还有二个月就快过年了。。。感慨一下
下面是今天用了一下午修改了下自己以前的网站后台ui,后台界面就不重新做了凑合着用了。。
主是把数据库的视图查询部分做了下,然后完善了下框架的路由!
PHP代码
- <?php
- class Model{
- public $db;
- public function __construct()
- {
- $this->db= new PDO(conf(‘dbType’).‘:host=’.conf(‘dbHost’).‘;dbname=’.conf(‘dbName’), conf(‘dbUser’), conf(‘dbPass’));
- $this->db->exec(‘SET NAMES ‘.conf(‘charset’));
- }
- function query($sql)
- {
- $rs = $this->db->query($sql);
- return $rs;
- }
- function beginTransaction()
- {
- return $this->db->beginTransaction();
- }
- function commit()
- {
- return $this->db->commit();
- }
- function rollBack()
- {
- return $this->db->rollBack();
- }
- function exec($sql)
- {
- return $this->db->exec($sql);
- }
- function lastInsertId()
- {
- return $this->db->lastInsertId();
- }
- function setAttribute($attr, $value)
- {
- return $this->db->setAttribute($attr, $value);
- }
- function insert($table,$data)
- {
- $table=conf(‘dbprefix’).$table;
- $fields = "";
- $values = "";
- foreach($data as $field=>$value)
- {
- $fields .= "`$field`, ";
- $values .= "’$value’, ";
- }
- $fields = substr_replace($fields, "", -2, 1);
- $values = substr_replace($values, "", -2, 1);
- $sql = "insert into `$table` ($fields) values ($values)";
- //echo $sql;
- $rs = $this->db->query($sql) ;
- return $this->db->lastInsertId();
- }
- function del($table,$keyarr){
- $table=conf(‘dbprefix’).$table;
- $where = "";
- foreach($keyarr as $key=>$key_value)
- {
- $where .= "`$key`=’$key_value’";
- }
- $sql = "delete from `$table` where $where";
- $rs = $this->db->query($sql);
- return $rs;
- }
- function update($table,$data, $keyarr)
- {
- $table=conf(‘dbprefix’).$table;
- $set = "";
- foreach($data as $field=>$value)
- {
- $set .= "`$field`=’$value’, ";
- }
- $set = substr_replace($set, "", -2, 1);
- $where = "";
- foreach($keyarr as $key=>$key_value)
- {
- $where .= "`$key`=’$key_value’";
- }
- $sql = "update `$table` set $set where $where";
- //echo $sql;
- $rs = $this->db->query($sql);
- return $rs;
- }
- function find($table,$where=”,$field=‘*’,$order=”,$group=”)
- {
- $sql=$this->_map($table,$where,$field,$order,”,$group);
- //echo $sql;
- return $this->_find($sql);
- }
- function findAll($table,$where=”,$field=‘*’,$order=”,$limit=”,$group=”)
- {
- $sql=$this->_map($table,$where,$field,$order,$limit,$group);
- return $this->_findAll($sql);
- }
- function count($table,$where=”,$field=‘*’,$order=”,$group=”)
- {
- $sql=$this->_map($table,$where,$field,$order,”,$group);
- return $this->_count($sql);
- }
- function _count($sql)
- {
- $rs=$this->query($sql);
- $count=$rs->fetchColumn();
- $count=emptyempty($count)?0:$count;
- return $count;
- }
- function _find($sql)
- {
- $rs=$this->query($sql);
- $row=$rs->fetch(PDO::FETCH_ASSOC);
- return $row;
- }
- function _findAll($sql)
- {
- $rs=$this->query($sql);
- $row=$rs->fetchall(PDO::FETCH_ASSOC);
- return $row;
- }
- function _map($table,$where=”,$field=‘*’,$order=”,$limit=”,$group=”)
- {
- $order=emptyempty($order)?”:‘order by ‘.$order;
- $limit=emptyempty($group)?”:‘limit ‘.$limit;
- $group=emptyempty($group)?”:‘group by ‘.$group;
- $w=”;
- if(!emptyempty($where)){
- if(is_array($where)){
- $w.=‘where’;
- foreach($where as $k=>$v){
- $w.=" $k=’$v’ and";
- }
- $w=substr($w,0,strlen($w)-3);
- }else{
- $w=$where;
- }
- }
- if(is_array($table)){
- $table1=conf(‘dbprefix’).$table[0];
- //echo $table1;
- $count=count($table);
- $joinleft=”;
- array_shift($table);
- foreach($table as $v){
- foreach($v as $k2=>$v2){
- $k2=conf(‘dbprefix’).$k2;
- foreach($v2 as $k3=>$v3){
- $l="$table1.$k3=$k2.$v3";
- }
- $joinleft.="left join $k2 on $l ";
- }
- }
- $sql="select $field from $table1 $joinleft $w $order $group $limit";
- }else{
- $sql="select $field from $table $w $order $group $limit";
- }
- return $sql;
- }
- }
- //fetch(‘PDO_FETCH_ASSOC’)
- ?>
网站后台界面 调整了部分css,对ff的兼容性更好些
网站的url形式
可否共享下程序呢?呵呵。