本文整理汇总了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).");
}
";
}
示例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).");
}
";
}
}
示例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);
}
}
}
示例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));
}
示例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;
}
示例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));
}
}
示例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)));
}
示例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));
}
示例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)));
}
}
示例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;
}
}
示例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));
}
示例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);
}
示例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();
}
示例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";
}
示例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";
}
}