今天开始写一个通用的企业网站程序

最近要帮我哥的公司做一个企业网站,再加以我叔公司的网站到现在还是半成品就挂到网上了,心中老是过意不去,但是自己都去好好解决一下,最近也有空了,准备花上一周左右的时间,把这两个企业网站做掉。

做完这二个网站后,自己也准备做一个网站自己用了,时间过得真快,还有二个月就快过年了。。。感慨一下

下面是今天用了一下午修改了下自己以前的网站后台ui,后台界面就不重新做了凑合着用了。。

主是把数据库的视图查询部分做了下,然后完善了下框架的路由!

 

PHP代码
  1. <?php  
  2. class Model{  
  3.   
  4.     public $db;  
  5.   
  6.     public function __construct()  
  7.     {  
  8.         $this->db= new PDO(conf(‘dbType’).‘:host=’.conf(‘dbHost’).‘;dbname=’.conf(‘dbName’), conf(‘dbUser’), conf(‘dbPass’));  
  9.         $this->db->exec(‘SET NAMES ‘.conf(‘charset’));   
  10.     }  
  11.   
  12.     function query($sql)  
  13.     {  
  14.         $rs = $this->db->query($sql);  
  15.         return $rs;  
  16.     }  
  17.   
  18.   
  19.     function beginTransaction()  
  20.     {  
  21.         return $this->db->beginTransaction();  
  22.     }  
  23.   
  24.     function commit()  
  25.     {  
  26.         return $this->db->commit();  
  27.     }  
  28.   
  29.     function rollBack()  
  30.     {  
  31.         return $this->db->rollBack();  
  32.     }  
  33.   
  34.     function exec($sql)  
  35.     {  
  36.         return $this->db->exec($sql);  
  37.     }  
  38.   
  39.     function lastInsertId()  
  40.     {  
  41.         return $this->db->lastInsertId();  
  42.     }  
  43.   
  44.   
  45.     function setAttribute($attr$value)  
  46.     {  
  47.         return $this->db->setAttribute($attr$value);  
  48.     }  
  49.   
  50.   
  51.     function insert($table,$data)  
  52.     {  
  53.         $table=conf(‘dbprefix’).$table;  
  54.         $fields = "";  
  55.         $values = "";  
  56.         foreach($data as $field=>$value)  
  57.         {  
  58.             $fields .= "`$field`, ";  
  59.             $values .= "’$value’, ";  
  60.         }  
  61.           
  62.         $fields = substr_replace($fields"", -2, 1);  
  63.         $values = substr_replace($values"", -2, 1);  
  64.   
  65.         $sql = "insert into `$table` ($fields) values ($values)";  
  66.         //echo $sql;  
  67.         $rs = $this->db->query($sql) ;  
  68.         return $this->db->lastInsertId();  
  69.     }  
  70.   
  71.     function del($table,$keyarr){  
  72.         $table=conf(‘dbprefix’).$table;  
  73.         $where = "";  
  74.         foreach($keyarr as $key=>$key_value)  
  75.         {  
  76.             $where .= "`$key`=’$key_value’";  
  77.         }  
  78.         $sql = "delete from `$table` where $where";  
  79.         $rs = $this->db->query($sql);  
  80.         return $rs;  
  81.     }  
  82.   
  83.     function update($table,$data$keyarr)  
  84.     {  
  85.         $table=conf(‘dbprefix’).$table;  
  86.         $set = "";  
  87.         foreach($data as $field=>$value)  
  88.         {  
  89.             $set .= "`$field`=’$value’, ";  
  90.         }  
  91.         $set = substr_replace($set"", -2, 1);  
  92.   
  93.         $where = "";  
  94.         foreach($keyarr as $key=>$key_value)  
  95.         {  
  96.             $where .= "`$key`=’$key_value’";  
  97.         }  
  98.           
  99.   
  100.         $sql = "update `$table` set $set where $where";  
  101.         //echo $sql;  
  102.         $rs = $this->db->query($sql);  
  103.           
  104.         return $rs;  
  105.     }  
  106.   
  107.     function find($table,$where=,$field=‘*’,$order=,$group=)  
  108.     {  
  109.         $sql=$this->_map($table,$where,$field,$order,,$group);  
  110.         //echo $sql;  
  111.         return $this->_find($sql);  
  112.     }  
  113.       
  114.     function findAll($table,$where=,$field=‘*’,$order=,$limit=,$group=)  
  115.     {  
  116.         $sql=$this->_map($table,$where,$field,$order,$limit,$group);  
  117.         return $this->_findAll($sql);  
  118.     }  
  119.   
  120.     function count($table,$where=,$field=‘*’,$order=,$group=)  
  121.     {  
  122.         $sql=$this->_map($table,$where,$field,$order,,$group);  
  123.         return $this->_count($sql);  
  124.     }  
  125.       
  126.     function _count($sql)  
  127.     {  
  128.         $rs=$this->query($sql);  
  129.         $count=$rs->fetchColumn();  
  130.         $count=emptyempty($count)?0:$count;  
  131.         return $count;  
  132.     }  
  133.       
  134.     function _find($sql)  
  135.     {  
  136.         $rs=$this->query($sql);  
  137.         $row=$rs->fetch(PDO::FETCH_ASSOC);  
  138.         return $row;  
  139.     }  
  140.       
  141.     function _findAll($sql)  
  142.     {  
  143.         $rs=$this->query($sql);  
  144.         $row=$rs->fetchall(PDO::FETCH_ASSOC);  
  145.         return $row;  
  146.     }  
  147.      
  148.     function _map($table,$where=,$field=‘*’,$order=,$limit=,$group=)  
  149.     {  
  150.         $order=emptyempty($order)?:‘order by ‘.$order;  
  151.         $limit=emptyempty($group)?:‘limit ‘.$limit;  
  152.         $group=emptyempty($group)?:‘group by ‘.$group;  
  153.         $w=;  
  154.           
  155.         if(!emptyempty($where)){  
  156.             if(is_array($where)){  
  157.                 $w.=‘where’;  
  158.                 foreach($where as $k=>$v){  
  159.                     $w.=" $k=’$v’ and";  
  160.                 }  
  161.                 $w=substr($w,0,strlen($w)-3);  
  162.             }else{  
  163.                 $w=$where;  
  164.             }  
  165.         }  
  166.           
  167.         if(is_array($table)){  
  168.             $table1=conf(‘dbprefix’).$table[0];  
  169.             //echo $table1;  
  170.             $count=count($table);  
  171.             $joinleft=;  
  172.             array_shift($table);  
  173.             foreach($table as $v){  
  174.                 foreach($v as $k2=>$v2){  
  175.                     $k2=conf(‘dbprefix’).$k2;  
  176.                     foreach($v2 as $k3=>$v3){  
  177.                         $l="$table1.$k3=$k2.$v3";  
  178.                     }  
  179.                     $joinleft.="left join $k2 on $l ";  
  180.                 }  
  181.                   
  182.             }  
  183.             $sql="select $field from $table1 $joinleft $w $order $group $limit";  
  184.         }else{  
  185.             $sql="select $field from $table $w  $order $group $limit";  
  186.         }  
  187.         return $sql;  
  188.     }  
  189.   
  190. }  
  191. //fetch(‘PDO_FETCH_ASSOC’)  
  192. ?>  

 

网站后台界面 调整了部分css,对ff的兼容性更好些

11.jpg

网站的url形式

2222.jpg

今天开始写一个通用的企业网站程序》有1个想法

评论已关闭。