当前位置: 首页>>代码示例>>PHP>>正文


PHP CModel类代码示例

本文整理汇总了PHP中CModel的典型用法代码示例。如果您正苦于以下问题:PHP CModel类的具体用法?PHP CModel怎么用?PHP CModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: clientValidateAttribute

	/**
	 * Returns the JavaScript needed for performing client-side validation.
	 * @param CModel $object the data object being validated
	 * @param string $attribute the name of the attribute to be validated.
	 * @return string the client-side validation script.
	 * @see CActiveForm::enableClientValidation
	 * @since 1.1.7
	 */
	public function clientValidateAttribute($object,$attribute)
	{
		if($this->pattern===null)
			throw new CException(Yii::t('yii','The "pattern" property must be specified with a valid regular expression.'));

		$message=$this->message!==null ? $this->message : Yii::t('yii','{attribute} is invalid.');
		$message=strtr($message, array(
			'{attribute}'=>$object->getAttributeLabel($attribute),
		));

		$pattern=$this->pattern;
		$pattern=preg_replace('/\\\\x\{?([0-9a-fA-F]+)\}?/', '\u$1', $pattern);
		$delim=substr($pattern, 0, 1);
		$endpos=strrpos($pattern, $delim, 1);
		$flag=substr($pattern, $endpos + 1);
		if ($delim!=='/')
			$pattern='/' . str_replace('/', '\\/', substr($pattern, 1, $endpos - 1)) . '/';
		else
			$pattern = substr($pattern, 0, $endpos + 1);
		if (!empty($flag))
			$pattern .= preg_replace('/[^igm]/', '', $flag);

		return "
if(".($this->allowEmpty ? "$.trim(value)!='' && " : '').($this->not ? '' : '!')."value.match($pattern)) {
	messages.push(".CJSON::encode($message).");
}
";
	}
开发者ID:alsvader,项目名称:hackbanero,代码行数:36,代码来源:CRegularExpressionValidator.php

示例2: clientValidateAttribute

	/**
	 * Returns the JavaScript needed for performing client-side validation.
	 * @param CModel $object the data object being validated
	 * @param string $attribute the name of the attribute to be validated.
	 * @return string the client-side validation script.
	 * @see CActiveForm::enableClientValidation
	 * @since 1.1.7
	 */
	public function clientValidateAttribute($object,$attribute)
	{
		$message=$this->message;
		if($this->requiredValue!==null)
		{
			if($message===null)
				$message=Yii::t('yii','{attribute} must be {value}.');
			$message=strtr($message, array(
				'{value}'=>$this->requiredValue,
				'{attribute}'=>$object->getAttributeLabel($attribute),
			));
			return "
if(value!=" . CJSON::encode($this->requiredValue) . ") {
	messages.push(".CJSON::encode($message).");
}
";
		}
		else
		{
			if($message===null)
				$message=Yii::t('yii','{attribute} cannot be blank.');
			$message=strtr($message, array(
				'{attribute}'=>$object->getAttributeLabel($attribute),
			));
			return "
if($.trim(value)=='') {
	messages.push(".CJSON::encode($message).");
}
";
		}
	}
开发者ID:alsvader,项目名称:hackbanero,代码行数:39,代码来源:CRequiredValidator.php

示例3: validateAttribute

 /**
  * Validates a single attribute.
  * 
  * @param CModel $object the data object being validated
  * @param string $attribute the name of the attribute to be validated.
  */
 protected function validateAttribute($object, $attribute)
 {
     $value = $object->{$attribute};
     if ($this->isEmpty($value)) {
         if ($this->allowEmpty) {
             return;
         } else {
             $arrValidators = $object->getValidators($attribute);
             foreach ($arrValidators as $objValidator) {
                 // do not duplicate error message if attribute is already required
                 if ($objValidator instanceof CRequiredValidator) {
                     return;
                 }
             }
             $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} cannot be blank.');
             $this->addError($object, $attribute, $message);
         }
     } else {
         $return = $this->validateIBAN($value);
         if (true !== $return) {
             $message = $this->message !== null ? $this->message : $this->getErrorMessage($return, $value);
             $this->addError($object, $attribute, $message);
         }
     }
 }
开发者ID:Diakonrus,项目名称:fastweb-yii,代码行数:31,代码来源:EIBANValidator.php

示例4: renderInput

 public function renderInput(CModel $model, $attribute, array $htmlOptions = array())
 {
     $action = new Actions();
     $action->setAttributes($model->getAttributes(), false);
     $defaultOptions = array('id' => $this->resolveId($attribute));
     $htmlOptions = X2Html::mergeHtmlOptions($defaultOptions, $htmlOptions);
     return preg_replace('/Actions(\\[[^\\]]*\\])/', get_class($this->formModel) . '$1', $action->renderInput($attribute, $htmlOptions));
 }
开发者ID:shuvro35,项目名称:X2CRM,代码行数:8,代码来源:ActionActiveFormBase.php

示例5: fieldClass

 /**
  * Returns input container class for any given attribute, depending on validation conditions.
  * @param CModel $model the data model
  * @param string $attribute the attribute name
  */
 public function fieldClass($model, $attribute)
 {
     $class = 'control-group';
     if ($model->getError($attribute)) {
         $class .= ' error';
     }
     return $class;
 }
开发者ID:rzamarripa,项目名称:masoftproyectos,代码行数:13,代码来源:BActiveForm.php

示例6: errorModelSummery

 /**
  * get error info from model
  * 
  * @param CModel $model
  * @return string
  * @see CModel
  */
 public static function errorModelSummery($model, $attribute = null)
 {
     if (is_null($attribute)) {
         return self::errorSummery($model->getErrors());
     } else {
         $aryError = $model->getError($attribute, false);
         return empty($aryError) ? '' : self::errorSummery(array($aryError));
     }
 }
开发者ID:erdincay,项目名称:WIIBOX,代码行数:16,代码来源:CHtml.php

示例7: getErrorMessage

 /**
  * Returns the validation error message.
  * @param CModel $object the data object being validated.
  * @param string $attribute the name of the attribute to be validated.
  * @return string the message.
  */
 public function getErrorMessage($object, $attribute)
 {
     if (isset($this->message)) {
         $message = $this->message;
     } else {
         $message = Yii::t('validator', 'This value must be repeated exactly.');
     }
     return strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute)));
 }
开发者ID:nordsoftware,项目名称:yii-parsley,代码行数:15,代码来源:ParsleyCompareValidator.php

示例8: validateAttribute

 /**
  * Validates the attribute of the object.
  * @param CModel $object the object being validated
  * @param string $attribute the attribute being validated
  */
 protected function validateAttribute($object, $attribute)
 {
     if ($this->setOnEmpty && !$this->isEmpty($object->{$attribute})) {
         return;
     }
     if (!$object->hasAttribute($this->translitAttribute)) {
         throw new CException(Yii::t('yiiext', 'Active record "{class}" is trying to select an invalid column "{column}". Note, the column must exist in the table or be an expression with alias.', array('{class}' => get_class($object), '{column}' => $this->translitAttribute)));
     }
     $object->{$attribute} = self::latin($object->getAttribute($this->translitAttribute));
 }
开发者ID:kosenka,项目名称:yboard,代码行数:15,代码来源:Translit.php

示例9: validateAttribute

 /**
  * Validates the attribute of the object.
  * If there is any error, the error message is added to the object.
  * @param CModel $object the object being validated
  * @param string $attribute the attribute being validated
  */
 protected function validateAttribute($object, $attribute)
 {
     $value = $object->{$attribute};
     if ($this->allowEmpty && $this->isEmpty($value)) {
         return;
     }
     if ($this->compareValue !== null) {
         $compareTo = $compareValue = $this->compareValue;
     } else {
         $compareAttribute = $this->compareAttribute === null ? $attribute . '_repeat' : $this->compareAttribute;
         $compareValue = $object->{$compareAttribute};
         $compareTo = $object->getAttributeLabel($compareAttribute);
     }
     switch ($this->operator) {
         case '=':
         case '==':
             if ($this->strict && $value !== $compareValue || !$this->strict && $value != $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be repeated exactly.');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo));
             }
             break;
         case '!=':
             if ($this->strict && $value === $compareValue || !$this->strict && $value == $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must not be equal to "{compareValue}".');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo, '{compareValue}' => $compareValue));
             }
             break;
         case '>':
             if ($value <= $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be greater than "{compareValue}".');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo, '{compareValue}' => $compareValue));
             }
             break;
         case '>=':
             if ($value < $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be greater than or equal to "{compareValue}".');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo, '{compareValue}' => $compareValue));
             }
             break;
         case '<':
             if ($value >= $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be less than "{compareValue}".');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo, '{compareValue}' => $compareValue));
             }
             break;
         case '<=':
             if ($value > $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be less than or equal to "{compareValue}".');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo, '{compareValue}' => $compareValue));
             }
             break;
         default:
             throw new CException(Yii::t('yii', 'Invalid operator "{operator}".', array('{operator}' => $this->operator)));
     }
 }
开发者ID:Jride,项目名称:accounting-thaiconnections,代码行数:61,代码来源:CCompareValidator.php

示例10: validateValue

 protected function validateValue(CModel $object, $value, $attribute)
 {
     // exception added for case where validator is added to AmorphousModel
     if (!$object instanceof X2Model) {
         return;
     }
     $field = $object->getField($attribute);
     $linkType = $field->linkType;
     $model = X2Model::model($linkType);
     if (!$model || !$model->findByPk($value)) {
         $this->error(Yii::t('admin', 'Invalid {fieldName}', array('{fieldName}' => $field->attributeLabel)));
         return false;
     }
 }
开发者ID:dsyman2,项目名称:X2CRM,代码行数:14,代码来源:X2ModelForeignKeyValidator.php

示例11: getErrorMessage

 /**
  * Returns the validation error message.
  * @param CModel $object the data object being validated.
  * @param string $attribute the name of the attribute to be validated.
  * @return string the message.
  */
 public function getErrorMessage($object, $attribute)
 {
     if (isset($this->message)) {
         $message = $this->message;
     } elseif (isset($this->min, $this->max)) {
         $message = Yii::t('validator', 'You must select between {min} and {max} choices.');
     } elseif (isset($this->min)) {
         $message = Yii::t('validator', 'You must select at least {min} choices.');
     } elseif (isset($this->max)) {
         $message = Yii::t('validator', 'You cannot have more than {max} choices selected.');
     } else {
         $message = Yii::t('validator', 'Invalid amount of choices selected.');
     }
     return strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute), '{min}' => $this->min, '{max}' => $this->max));
 }
开发者ID:nordsoftware,项目名称:yii-parsley,代码行数:21,代码来源:ParsleyCheckboxValidator.php

示例12: beginControlGroup

 public function beginControlGroup(CModel $model, $attributes, $htmlOptions = array())
 {
     if (!isset($htmlOptions['class'])) {
         $htmlOptions['class'] = 'control-group';
     }
     if (!is_array($attributes)) {
         $attributes = explode(',', str_replace(' ', '', $attributes));
     }
     foreach ($attributes as $attr) {
         if ($model->hasErrors($attr)) {
             $htmlOptions['class'] .= ' error';
         }
     }
     return CHtml::tag('div', $htmlOptions, false, false);
 }
开发者ID:jankichaudhari,项目名称:yii-site,代码行数:15,代码来源:AdminForm.php

示例13: Action_index

 public function Action_index()
 {
     // 检测用户是否登录
     if (AdminController::isLogin()) {
         return CResponse::getInstance()->redirect(array('c' => 'admin', 'a' => 'index'));
     }
     if ($_POST) {
         // 获取参数
         $username = $this->Args('username', 'string');
         $password = $this->Args('password', 'string');
         // 检查登陆
         $userCheckStatus = CModel::factory('adminUserModel')->userCheck($username, $password);
         // 检查失败
         if (false == $userCheckStatus['status']) {
             // 登录失败
             $this->assign('userLoginStatus', $userCheckStatus);
         } else {
             // 允许登陆
             $userLoginStatus = CModel::factory('adminUserModel')->userLogin($userCheckStatus);
             if ($userLoginStatus['status'] == false) {
                 $this->assign('userLoginStatus', $userLoginStatus);
             } else {
                 // 登录成功
                 CResponse::getInstance()->redirect($userLoginStatus['urlPram']);
             }
         }
     }
     $this->display();
 }
开发者ID:seiven,项目名称:ACEAdminForMyframework,代码行数:29,代码来源:base.php

示例14: clientValidateAttribute

 /**
  * Returns the JavaScript needed for performing client-side validation.
  * @param CModel $object the data object being validated
  * @param string $attribute the name of the attribute to be validated.
  * @return string the client-side validation script.
  * @see CActiveForm::enableClientValidation
  * @since 1.1.7
  */
 public function clientValidateAttribute($object, $attribute)
 {
     if (!is_array($this->range)) {
         throw new CException(Yii::t('yii', 'The "range" property must be specified with a list of values.'));
     }
     if (($message = $this->message) === null) {
         $message = $this->not ? Yii::t('yii', '{attribute} is in the list.') : Yii::t('yii', '{attribute} is not in the list.');
     }
     $message = strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute)));
     $range = array();
     foreach ($this->range as $value) {
         $range[] = (string) $value;
     }
     $range = CJSON::encode($range);
     return "\nif(" . ($this->allowEmpty ? "\$.trim(value)!='' && " : '') . ($this->not ? "\$.inArray(value, {$range})>=0" : "\$.inArray(value, {$range})<0") . ") {\n\tmessages.push(" . CJSON::encode($message) . ");\n}\n";
 }
开发者ID:nizsheanez,项目名称:blog.ru,代码行数:24,代码来源:CRangeValidator.php

示例15: clientValidateAttribute

 /**
  * Returns the JavaScript needed for performing client-side validation.
  * @param CModel $object the data object being validated
  * @param string $attribute the name of the attribute to be validated.
  * @return string the client-side validation script.
  * @see CActiveForm::enableClientValidation
  * @since 1.1.7
  */
 public function clientValidateAttribute($object, $attribute)
 {
     $message = $this->message;
     if ($this->requiredValue !== null) {
         if ($message === null) {
             $message = Yii::t('yii', '{attribute} phải là {value}.');
         }
         $message = strtr($message, array('{value}' => $this->requiredValue, '{attribute}' => $object->getAttributeLabel($attribute)));
         return "\nif(value!=" . CJSON::encode($this->requiredValue) . ") {\n\tmessages.push(" . CJSON::encode($message) . ");\n}\n";
     } else {
         if ($message === null) {
             $message = Yii::t('yii', '{attribute} không thể trống.');
         }
         $message = strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute)));
         return "\nif(jQuery.trim(value)=='') {\n\tmessages.push(" . CJSON::encode($message) . ");\n}\n";
     }
 }
开发者ID:huydoan95,项目名称:huydoan95.github.hotrosvtdmu,代码行数:25,代码来源:CRequiredValidator.php


注:本文中的CModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。