本文整理汇总了PHP中CModel::getAttributeLabel方法的典型用法代码示例。如果您正苦于以下问题:PHP CModel::getAttributeLabel方法的具体用法?PHP CModel::getAttributeLabel怎么用?PHP CModel::getAttributeLabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CModel
的用法示例。
在下文中一共展示了CModel::getAttributeLabel方法的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)
{
$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).");
}
";
}
}
示例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)
{
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).");
}
";
}
示例3: 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";
}
}
示例4: 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 is not a valid phone number.');
}
return strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute)));
}
示例5: 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)));
}
}
示例6: 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', 'The value must gave between {min} and {max} characters.');
} elseif (isset($this->min)) {
$message = Yii::t('validator', 'The value is too short (minimum is {min} characters).');
} elseif (isset($this->max)) {
$message = Yii::t('validator', 'The value is too long (maximum is {max} characters).');
} else {
$message = Yii::t('validator', 'The value is invalid.');
}
return strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute), '{min}' => $this->min, '{max}' => $this->max));
}
示例7: 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";
}
示例8: 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)
{
if ($this->otherFieldValue === false && !$object->{$this->otherField}) {
return;
}
if ($this->otherFieldValue === false || $object->{$this->otherField} == $this->otherFieldValue || is_array($this->otherFieldValue) && in_array($object->{$this->otherField}, $this->otherFieldValue)) {
$otherFieldLabel = $object->getAttributeLabel($this->otherField);
$otherFieldValueLabel = $this->otherFieldValue ? $this->otherFieldValue : Yii::t('dressing', 'not blank');
$value = $object->{$attribute};
if ($this->requiredValue !== null) {
if (!$this->strict && $value != $this->requiredValue || $this->strict && $value !== $this->requiredValue) {
$message = $this->message !== null ? $this->message : Yii::t('dressing', '{attribute} must be {value} when {otherFieldLabel} is {otherFieldValueLabel}.', array('{value}' => $this->requiredValue, '{otherFieldLabel}' => $otherFieldLabel, '{otherFieldValueLabel}' => $otherFieldValueLabel));
$this->addError($object, $attribute, $message);
}
} else {
if ($this->isEmpty($value, true)) {
$message = $this->message !== null ? $this->message : Yii::t('dressing', '{attribute} cannot be blank when {otherFieldLabel} is {otherFieldValueLabel}.', array('{otherFieldLabel}' => $otherFieldLabel, '{otherFieldValueLabel}' => $otherFieldValueLabel));
$this->addError($object, $attribute, $message);
}
}
}
}
示例9: 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 "\r\nif(value!=" . CJSON::encode($this->requiredValue) . ") {\r\n\tmessages.push(" . CJSON::encode($message) . ");\r\n}\r\n";
} else {
if ($message === null) {
$message = Yii::t('yii', '{attribute} cannot be blank.');
}
$message = strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute)));
if ($this->trim) {
$emptyCondition = "jQuery.trim(value)==''";
} else {
$emptyCondition = "value==''";
}
return "\r\nif({$emptyCondition}) {\r\n\tmessages.push(" . CJSON::encode($message) . ");\r\n}\r\n";
}
}
示例10: 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)
{
$js = '';
if (!$this->allowEmpty) {
$message = $this->message;
if ($message == null) {
$message = Yii::t('yii', '{attribute} cannot be blank.');
}
$message = strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute)));
$js .= '
if($.trim(value)==""){messages.push(' . CJSON::encode($message) . ');}
';
}
if ($this->types !== null) {
if (is_string($this->types)) {
$types = preg_split('/[\\s,]+/', strtolower($this->types), -1, PREG_SPLIT_NO_EMPTY);
} else {
$types = $this->types;
}
$message = $this->wrongType;
if ($message == null) {
$message = Yii::t('yii', 'The file "{file}" cannot be uploaded. Only files with these extensions are allowed: {extensions}.');
}
$message = strtr($message, array('{file}' => ':file', '{extensions}' => implode(', ', $types)));
$js .= "\r\n if(['" . implode("','", $types) . "'].indexOf(\$.trim(value).split('.').pop().toLowerCase()) == -1" . ($this->allowEmpty ? " && \$.trim(value)!=''" : '') . ")\r\n {\r\n messages.push('" . $message . "'.replace(':file', \$.trim(value)));\r\n }\r\n ";
}
/**
* Check the maxfile size setting
*/
if ($this->maxSize !== null) {
$message = $this->tooLarge !== null ? $this->tooLarge : Yii::t('yii', 'The file "{file}" is too large. Its size cannot exceed {limit} bytes.');
$message = strtr($message, array('{file}' => ':file', '{limit}' => $this->getReadableFileSize($this->getSizeLimit())));
$inputId = get_class($object) . "_" . $attribute;
$js .= "\r\n if (\$('#{$inputId}')[0].files[0]){\r\n var fileSize = \$('#{$inputId}')[0].files[0].size; \r\n if(fileSize>{$this->maxSize}){\r\n messages.push('" . $message . "'.replace(':file', \$.trim(value)));\r\n }\r\n }\r\n ";
}
return $js;
}
示例11: 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)
{
$captcha = $this->getCaptchaAction();
$message = $this->message !== null ? $this->message : Yii::t('yii', 'The verification code is incorrect.');
$message = strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute)));
$code = $captcha->getVerifyCode(false);
$hash = $captcha->generateValidationHash($this->caseSensitive ? $code : strtolower($code));
$js = "\r\nvar hash = jQuery('body').data('{$this->captchaAction}.hash');\r\nif (hash == null)\r\n\thash = {$hash};\r\nelse\r\n\thash = hash[" . ($this->caseSensitive ? 0 : 1) . "];\r\nfor(var i=value.length-1, h=0; i >= 0; --i) h+=value." . ($this->caseSensitive ? '' : 'toLowerCase().') . "charCodeAt(i);\r\nif(h != hash) {\r\n\tmessages.push(" . CJSON::encode($message) . ");\r\n}\r\n";
if ($this->allowEmpty) {
$js = "\r\nif(jQuery.trim(value)!='') {\r\n\t{$js}\r\n}\r\n";
}
return $js;
}
示例12: 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->validateIDN) {
Yii::app()->getClientScript()->registerCoreScript('punycode');
// punycode.js works only with the domains - so we have to extract it before punycoding
$validateIDN = '
var info = value.match(/^(.+:\\/\\/|)([^/]+)/);
if (info)
value = info[1] + punycode.toASCII(info[2]);
';
} else {
$validateIDN = '';
}
$message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} is not a valid URL.');
$message = strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute)));
if (strpos($this->pattern, '{schemes}') !== false) {
$pattern = str_replace('{schemes}', '(' . implode('|', $this->validSchemes) . ')', $this->pattern);
} else {
$pattern = $this->pattern;
}
$js = "\n{$validateIDN}\nif(!value.match({$pattern})) {\n\tmessages.push(" . CJSON::encode($message) . ");\n}\n";
if ($this->defaultScheme !== null) {
$js = "\nif(!value.match(/:\\/\\//)) {\n\tvalue=" . CJSON::encode($this->defaultScheme) . "+'://'+value;\n}\n{$js}\n";
}
if ($this->allowEmpty) {
$js = "\nif(jQuery.trim(value)!='') {\n\t{$js}\n}\n";
}
return $js;
}
示例13: renderGroup
/**
* @param string $method the CActiveForm method name, e.g. textField, dropDownList, etc.
* @param CModel $model the form model
* @param string $attribute the attribute name
* @param bool|array $listOptions list options or false if none
* @param array $options group options
* @return string the rendered form group
*/
protected function renderGroup($method, $model, $attribute, $listOptions, $options)
{
if (isset($options['label']) && $options['label'] === false) {
$beginLabel = $endLabel = $labelTitle = $label = '';
} else {
$beginLabel = \CHtml::openTag('label', $options['labelOptions']);
$endLabel = \CHtml::closeTag('label');
$labelTitle = isset($options['label']) ? $options['label'] : $model->getAttributeLabel($attribute);
$label = \CHtml::tag('label', $options['labelOptions'], $labelTitle);
}
$beginWrapper = \CHtml::openTag($options['wrapperTag'], $options['wrapperOptions']);
$endWrapper = \CHtml::closeTag($options['wrapperTag']);
if ($model->hasErrors($attribute) && $options['enableErrorBlock']) {
$error = \CHtml::tag($options['errorTag'], $options['errorOptions'], $model->getError($attribute));
$options['groupOptions']['class'] = isset($options['groupOptions']['class']) ? $options['groupOptions']['class'] . ' has-error' : 'has-error';
} else {
$error = '';
}
$help = isset($options['helpText']) ? \CHtml::tag($options['helpTag'], $options['helpOptions'], $options['helpText']) : '';
if ($this->layout === 'inline' && !isset($options['inputOptions']['placeholder'])) {
$options['inputOptions']['placeholder'] = $labelTitle;
}
if ($listOptions) {
$input = parent::$method($model, $attribute, $listOptions, $options['inputOptions']);
} else {
$input = parent::$method($model, $attribute, $options['inputOptions']);
}
if (isset($options['inputTemplate'])) {
$input = strtr($options['inputTemplate'], array('{input}' => $input));
}
$content = strtr($options['template'], array('{label}' => $label, '{beginLabel}' => $beginLabel, '{labelTitle}' => $labelTitle, '{endLabel}' => $endLabel, '{beginWrapper}' => $beginWrapper, '{endWrapper}' => $endWrapper, '{input}' => $input, '{error}' => $error, '{help}' => $help));
return \CHtml::tag($options['groupTag'], $options['groupOptions'], $content);
}
示例14: 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)) {
if ($this->integerOnly) {
$message = Yii::t('validator', 'The value must be an integer between {min} and {max}.');
} else {
$message = Yii::t('validator', 'The value must be a number between {min} and {max}.');
}
} elseif (isset($this->min)) {
$message = Yii::t('validator', 'The value is too small (minimum is {min}).');
} elseif (isset($this->min)) {
$message = Yii::t('validator', 'The value is too big (maximum is {max}).');
} elseif ($this->integerOnly) {
$message = Yii::t('validator', 'The value must be an integer.');
} else {
$message = Yii::t('validator', 'The value must be a number.');
}
return strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute), '{min}' => $this->min, '{max}' => $this->max));
}
示例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 !== null ? $this->message : Yii::t('yii', '{attribute} must be either {true} or {false}.');
$message = strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute), '{true}' => $this->trueValue, '{false}' => $this->falseValue));
return "\nif(" . ($this->allowEmpty ? "\$.trim(value)!='' && " : '') . "value!=" . CJSON::encode($this->trueValue) . " && value!=" . CJSON::encode($this->falseValue) . ") {\n\tmessages.push(" . CJSON::encode($message) . ");\n}\n";
}