<?php

namespace Common\Model;

use Common\Model\CommonModel;

class MGameModel extends CommonModel{
	//自动验证
	protected $_validate = array(
			//array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
			array('gamename', 'require', '游戏名称不能为空！', 1, 'regex', 3),
            array('gamename', 'checkName', '同样的游戏名称已经存在！', 1, 'callback', CommonModel:: MODEL_BOTH),
	);

	protected $_auto = array(
			array('addtime','time',1,'function')
	);
    //验证gamename是否重复添加
    public function checkName() {
    	$map['gamename'] = I('post.gamename');
        $id = I('post.id');
        if(!empty($id)){
            $map['id'] = array('neq', $id);
        }
    	$res = $this->where($map)->find();
        return empty($res);
    }
	protected function _before_write(&$data) {
		parent::_before_write($data);

	}

}