|
@@ -3,9 +3,8 @@
|
|
|
* 核心文件
|
|
|
*
|
|
|
* 模型类
|
|
|
- *
|
|
|
- * @package core* www.abc.com 专业团队 提供售后服务
|
|
|
*/
|
|
|
+
|
|
|
class Model
|
|
|
{
|
|
|
protected $name = '';
|
|
@@ -112,7 +111,9 @@ class Model
|
|
|
}
|
|
|
}
|
|
|
return $this;
|
|
|
- }elseif(in_array(strtolower($method),array('page'),true)){
|
|
|
+ }
|
|
|
+ elseif(in_array(strtolower($method),array('page'),true))
|
|
|
+ {
|
|
|
if ($args[0] == null){
|
|
|
return $this;
|
|
|
}elseif(!is_numeric($args[0]) || $args[0] <= 0){
|
|
@@ -136,10 +137,14 @@ class Model
|
|
|
$this->unoptions = false;
|
|
|
pagecmd('setTotalNum', $this->get_field('COUNT(*) AS nc_count'));
|
|
|
return $this;
|
|
|
- }elseif(in_array(strtolower($method),array('min','max','count','sum','avg'),true)){
|
|
|
+ }
|
|
|
+ elseif(in_array(strtolower($method),array('min','max','count','sum','avg'),true))
|
|
|
+ {
|
|
|
$field = isset($args[0])?$args[0]:'*';
|
|
|
return $this->get_field(strtoupper($method).'('.$field.') AS nc_'.$method);
|
|
|
- }elseif(strtolower($method)=='count1'){
|
|
|
+ }
|
|
|
+ elseif(strtolower($method)=='count1')
|
|
|
+ {
|
|
|
$field = isset($args[0])?$args[0]:'*';
|
|
|
$options['field'] = ('count('.$field.') AS nc_count');
|
|
|
$options = $this->parse_options($options);
|
|
@@ -148,11 +153,15 @@ class Model
|
|
|
if(!empty($result)) {
|
|
|
return reset($result[0]);
|
|
|
}
|
|
|
- }elseif(strtolower(substr($method,0,6))=='getby_') {
|
|
|
+ }
|
|
|
+ elseif(strtolower(substr($method,0,6))=='getby_')
|
|
|
+ {
|
|
|
$field = substr($method,6);
|
|
|
$where[$field] = $args[0];
|
|
|
return $this->where($where)->find();
|
|
|
- }elseif(strtolower(substr($method,0,7))=='getfby_') {
|
|
|
+ }
|
|
|
+ elseif(strtolower(substr($method,0,7))=='getfby_')
|
|
|
+ {
|
|
|
$name = substr($method,7);
|
|
|
$where[$name] =$args[0];
|
|
|
//getfby_方法只返回第一个字段值
|
|
@@ -160,7 +169,9 @@ class Model
|
|
|
$args[1] = substr($args[1],0,strpos($args[1],','));
|
|
|
}
|
|
|
return $this->where($where)->get_field($args[1]);
|
|
|
- }else{
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
$error = 'Model Error: Function '.$method.' is not exists!';
|
|
|
throw_exception($error);
|
|
|
return;
|
|
@@ -201,7 +212,8 @@ class Model
|
|
|
if(empty($resultSet)) {
|
|
|
return array();
|
|
|
}
|
|
|
- if ($options['key'] != '' && is_array($resultSet)){
|
|
|
+ if ($options['key'] != '' && is_array($resultSet))
|
|
|
+ {
|
|
|
$tmp = array();
|
|
|
foreach ($resultSet as $value) {
|
|
|
$tmp[$value[$options['key']]] = $value;
|