ThinkPHP下MongoDB的操作方法

https://github.com/liu21st/thinkphp/commits/master/ThinkPHP/Library/Think/Db/Driver/Mongo.class.php?author=vus520
向tp添加了一些mongodb操作方法,demo如下

Model

<?php
namespace Home\Model;
use Think\Model\MongoModel;
class UserActlogModel extends MongoModel
{
	
}

Controller

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller
{
	function index()
	{
		echo __CLASS__ .'\\'. __FUNCTION__;
	}

	function hello()
	{
		echo "Hello world";
	}

    public function mongo()
    {
    	$model = D("UserActLog");

    	//distinct查询语法,支持where、cache操作链
    	$result = $model->cache(false)->where( array('device.channelid'=>"10017") )->distinct('device.imei', array("day"=>"20140706"));
    	print_r(count($result));
    	print_r($model->_sql());
    	echo PHP_EOL;

    	//command查询语法
    	$data = $model->command(array('buildInfo'=>1));
    	//print_r($data);
    	print_r($model->_sql());
    	echo PHP_EOL;

    	$data = $model->status();
    	//print_r($data);
    	print_r($model->_sql());
    	echo PHP_EOL;

    	//MapReduce查询语法
    	$key    = array('device.channelid'=>1);
    	$init   = array('num'=>0);
    	$reduce = "function(obj, prev){prev.num++;}";
    	$option = array(
    			'table' => 'user_act_log',
    			'condition'=>array("day"=>"20140701"),
    	);
    	$result = $model->cache(true)->where( array("day"=>"20140708") )->group($key, $init, $reduce);
    	print_r(count($result));
    	print_r($model->_sql());
    	echo PHP_EOL;

    	//find查询语法,支持where、order、cache、field操作链
    	//field方法支持field("act,group"),field(array("act"=>true, "_id"=>false)),field(array("act", "group"))
    	$result = $model->where(array("day"=>"20140701"))->field(array("act"=>true, "group"=>true, "_id"=>false))->order('_id asc')->find();
    	print_r($result);
    	print_r($model->_sql());
    	echo PHP_EOL;

		//子查询OR逻辑
		$map['device.channel'] = "obx_03";
		$map['_logic'] = 'and';
		$map['_complex'] = array("act"=>"down", "group"=>"download", '_logic'=>"or");
		$result = $model->field(array("act"=>true, "group"=>true, "_id"=>false))->where($map)->limit(2)->select();
		print_r($result);
		print_r($model->_sql());
		echo PHP_EOL;

		//子查询OR逻辑
		$map['_complex'] = array('_logic'=>"or", array("act"=>"down"), array("group"=>"download"));
		$result = $model->where($map)->find();
		print_r($result);
		print_r($model->_sql());
		echo PHP_EOL;

		//子查询OR逻辑
    	$map = array();
    	$map['_complex'] = array('_logic'=>"or", array("act"=>"down"), array("group"=>"download"));
    	$result = $model->field(array("act"=>true, "group"=>true, "_id"=>false))->where($map)->find();
    	print_r($result);
    	print_r($model->_sql());
    	echo PHP_EOL;

    	//子查询 AND 逻辑
    	$map = array();
    	$map['_complex'] = array('_logic'=>"and", array("act"=>"down"), array("group"=>"download"));
    	$result = $model->field(array("act"=>true, "group"=>true, "_id"=>true))->where($map)->find();
    	print_r($result);
    	print_r($model->_sql());
    	echo PHP_EOL;

    	//子查询 nor 逻辑
    	$map = array();
    	$map['_complex'] = array('_logic'=>"nor", array("act"=>"down"), array("group"=>"download"));
    	$result = $model->field(array("act"=>true, "group"=>true, "_id"=>true))->where($map)->find();
    	print_r($result);
    	print_r($model->_sql());
    	echo PHP_EOL;

    	//$not查询
    	$map = array();
    	$map['day'] = '20140710';
    	$map['act'] = array('$exists'=>true, '$not'=>array('$in'=>array("click", "listview")) );
    	$map['_complex'] = array('_logic'=>"nor", array("act"=>"down"), array("group"=>"download"));
    	$result = $model->field(array("act"=>true, "group"=>true, "_id"=>true))->where($map)->find();
    	print_r($result);
    	print_r($model->_sql());
    	echo PHP_EOL;

    	//$not查询
    	$map = array();
    	$map['day'] = '20140710';
    	$map['_logic'] = 'or';
    	$map['act'] = array('$exists'=>true, '$not'=>array('$in'=>array("click", "listview")) );
    	$map['_complex'] = array('_logic'=>"nor", array("act"=>"down"), array("group"=>"download"));
    	$result = $model->field(array("act"=>true, "group"=>true, "_id"=>true))->where($map)->find();
    	print_r($result);
    	print_r($model->_sql());
    	echo PHP_EOL;
    }
}

ThinkPHP 2.1RC 的自动验证的小BUG。

Windows上:
UserlistModel.class.php

<?php
class UserlistModel extends Model {

// 自动验证设置
protected $_validate = array(
array('u_email','email','请您正确填写邮件地址!'),
array('u_name','require','请您正确填写姓名!'),
array('u_phone','number','请您正确填写手机号码'),
array('u_age','number','请您填写正确的年龄,只能填写数字!'),
array('sourceid','number','请正确选择您所在的城市!'),
);

// 自动填充设置
protected $_auto = array(
array('ifcheck','0',self::MODEL_INSERT),
array('dateline','time',self::MODEL_INSERT,'function'),
);

}
?>

移植到Linux上,自动验证不自动启动,检查了一下,发现是文件名的问题,修改文件名为小写以后,问题解决。
Linux上:
userlistModel.class.php

这个问题不知道有没有其它兄弟遇上,茫然中,求确认。

后确认此纠结源于TP未对自动验证的文件名做出验证,跟踪时也不会提示有错误。

正确的解决办法是严格按照TP的语法创建模型。
如:

$m = D("userlist");

$m = D("Userlist");

按TP的标准语法,应该是后者,对应的是UserlistModel.class.php。

如是,这里的大小写标准有增加开发成本的嫌疑!