本文整理匯總了PHP中Attribute::validate方法的典型用法代碼示例。如果您正苦於以下問題:PHP Attribute::validate方法的具體用法?PHP Attribute::validate怎麽用?PHP Attribute::validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Attribute
的用法示例。
在下文中一共展示了Attribute::validate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: actionCreate
public function actionCreate()
{
$model = new Attribute();
$description = new AttributeDescription();
$this->performAjaxValidation(array($model, $description), 'attribute-form');
if (isset($_POST[$this->modelName])) {
$model->setAttributes($_POST[$this->modelName]);
$description->setAttributes($_POST[$this->modelName . 'Description']);
$suc = Yii::t('info', 'Attribute was successfully created');
$err = Yii::t('info', 'Could not update Attribute');
$description->attribute_id = 0;
$description->locale_code = Yii::app()->getLanguage();
if ($model->validate() && $description->validate()) {
if ($model->save()) {
$description->attribute_id = $model->id;
$description->save();
Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, $suc);
if (Yii::app()->getRequest()->getIsAjaxRequest()) {
$this->renderPartial('_view', array('model' => $model, 'description' => $description), false, true);
Yii::app()->end();
} else {
$this->redirect(array('view', 'id' => $model->id));
}
} else {
Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, $err);
}
} else {
$description->validate();
}
}
if (Yii::app()->getRequest()->getIsAjaxRequest()) {
$this->renderPartial('_form', array('model' => $model, 'description' => $description), false, true);
Yii::app()->end();
}
$this->render('create', array('model' => $model, 'description' => $description));
}
示例2: test_private_attribute_should_fail_if_not_valid
public function test_private_attribute_should_fail_if_not_valid()
{
$subValidator = new Length(33333, 888888);
$validator = new Attribute('bar', $subValidator);
$obj = new PrivClass();
$this->assertFalse($validator->validate($obj));
}