<?php
namespace Common\Model;
use Common\Model\CommonModel;
class CardTypeModel extends CommonModel {
	
	//自动验证
	protected $_validate = array(
			//array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
			array('cardname', 'require', '分类名称不能为空！', 1, 'regex', CommonModel:: MODEL_BOTH ),
			array('cardname','check_tid','相同卡类类型名称已经存在！',1,'callback',CommonModel:: MODEL_BOTH),

	);
	
	function check_tid(){
  	    $tid['cardname'] = I('post.cardname');
  	    $tid['tid'] = I('post.tid');
        $id = I('post.id');
        if(!empty($id)){
            $tid['id'] = array('neq', $id);
        }
    	$res = $this->where($tid)->find();
        return empty($res);
	}
	protected function _before_write(&$data) {
		parent::_before_write($data);
	}
}