本文整理汇总了PHP中yii\db\ActiveRecord::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::validate方法的具体用法?PHP ActiveRecord::validate怎么用?PHP ActiveRecord::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::validate方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testUpdate
/**
* @covers \opus\base\behaviors\TimestampBehavior::inject
*/
public function testUpdate()
{
$now = new Expression('NOW()');
$this->mock->expects($this->once())->method('getIsNewRecord')->will($this->returnValue(false));
$this->mock->expects($this->any())->method('hasAttribute')->will($this->returnValue(true));
$this->mock->expects($this->once())->method('setAttribute')->with('up', $now);
$this->mock->validate();
}
示例2: validate
public function validate()
{
if (!$this->_instance->validate()) {
DI::getImporter()->wrongModel = $this->_instance;
throw new RowException($this->row, 'Model data is not valid.');
}
}
示例3: validate
public function validate($attributeNames = null, $clearErrors = true){
if(parent::validate($attributeNames, $clearErrors)){
Auction::infoLog('Model :: ' . self::className() . ' Has Successfully Validated ', $this->getAttributes());
return true;
}else{
Auction::errorLog('Model record :: '. self::className() .' not validated ',$this->getErrors());
return false;
}
}
示例4: validate
public function validate($attributeNames = null, $clearErrors = true)
{
if (Tag::findOne(['name' => $this->name, 'user_id' => $this->user_id])) {
$this->addError('name', 'Данный тег уже существует');
}
if (mb_strpos($this->name, ' ', null, 'utf-8') != false) {
$this->addError('name', 'Тег не должен содержать пробелы');
}
return parent::validate($attributeNames, false);
}
示例5: searchQuery
/**
* @param ActiveRecord $model
* @param array $opts
* @return ActiveQuery | array
*/
static function searchQuery($model, $opts = [])
{
$opts = ArrayHelper::merge(['data' => null, 'query' => null, 'columns' => [], 'filters' => []], $opts);
$columns = $opts['columns'];
$filters = $opts['filters'];
$data = $opts['data'];
if (null === $data) {
$data = \Yii::$app->request->get();
}
$query = $opts['query'];
if (is_string($query)) {
$query = call_user_func([$model, $opts['query']]);
} elseif (null === $query) {
$query = $model->find();
foreach (array_filter($model->getAttributes()) as $prop => $val) {
$query->andWhere([$prop => $val]);
}
}
if ($model->load($data) && $model->validate()) {
foreach ($model->getAttributes($model->safeAttributes()) as $name => $value) {
if ($model->isAttributeChanged($name)) {
$attributeTypes = [];
if (method_exists($model, 'attributeTypes')) {
$attributeTypes = $model->attributeTypes();
}
$type = null;
if (isset($attributeTypes[$name])) {
$type = $attributeTypes[$name];
}
// Default filter function
$filterFunc = isset($filters[$name]) && is_callable($filters[$name]) ? $filters[$name] : function (ActiveQuery $query, $name, $value, $type) {
/**
* @var string $name
* @var string|array $value
* @var string $type
*/
$query->andFilterWhere(static::searchAttribute($name, $value, $type));
};
if (isset($columns[$name])) {
$name = $columns[$name];
}
call_user_func($filterFunc, $query, $name, $value, $type);
}
}
}
return $query;
}
示例6: editModel
/**
* @param ActiveRecord $model
* @return string|\yii\web\Response
*/
protected function editModel($model)
{
// validate() && save(false) because of CantSave exception
if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->save(false)) {
return $this->redirect($this->getReturnUrl());
} else {
return $this->render($this->formView, ['model' => $model, 'returnUrl' => $this->getReturnUrl(), 'modelTitleForms' => $this->modelTitleForms, 'formElements' => $this->getFormElements($model)]);
}
}
示例7: update
public function update($runValidation = true, $attributeNames = null){
$this->image = UploadedFile::getInstance($this->user0, 'profile_pic');
if(!parent::validate())
return false;
if($this->image instanceof UploadedFile){
if(!getimagesize($this->image->tempName)){
$this->addError('image','Please Upload a valid Image');
return false;
}
Auction::info('Image Upload Event Triggered');
$this->trigger(Events::UPLOAD_IMAGE);
parent::update(false);
$this->user0->profile_pic = $this->image;
}
else{
$this->user0->profile_pic = $this->user0->oldAttributes['profile_pic'];
}
if($this->user0->save(false)) {
Auction::info('Dealer is successsfully Updated');
return true;
}else{
Auction::infoLog('Dealer is not updated Due to following validation Errors',$this->user0->getErrors());
return false;
}
}
示例8: validate
/**
* need to validate the relation models
* @inheritdoc
*/
public function validate($attributes = null, $clearErrors = true)
{
$isValid = parent::validate($attributes, $clearErrors);
$relatedAttributes = [];
if ($attributes) {
foreach ($attributes as $attribute) {
if (($pos = strpos($attribute, '.')) !== false) {
$relatedName = substr($attributes, 0, $pos + 1);
$relatedAttribute = substr($attributes, $pos + 2);
if (!isset($relatedAttributes[$relatedName])) {
$relatedAttributes[$relatedName] = [];
}
$relatedAttributes[$relatedName][] = $relatedAttribute;
}
}
}
foreach ($this->_relations as $name => $models) {
$modelAttributes = isset($relatedAttributes[$name]) ? $relatedAttributes[$name] : null;
if (is_array($models)) {
foreach ($models as $model) {
/** @var \yii\db\ActiveRecord $model */
if (!$model->validate($modelAttributes, $clearErrors)) {
$isValid = false;
$this->addError($name, $model->getErrors());
}
}
} else {
/** @var \yii\db\ActiveRecord $models */
if (!$models->validate($modelAttributes, $clearErrors)) {
$isValid = false;
$this->addError($name, $models->getErrors());
}
}
}
return $isValid;
}
示例9: validate
/**
* need to validate the relation models
* @inheritdoc
*/
public function validate($attributes = null, $clearErrors = true)
{
$isValid = true;
if (!parent::validate($attributes, $clearErrors)) {
$isValid = false;
}
foreach ($this->_relations as $name => $models) {
if (is_array($models)) {
foreach ($models as $model) {
/** @var \yii\db\ActiveRecord $model */
if (!$model->validate(null, $clearErrors)) {
$isValid = false;
$this->addError($name, $model->getErrors());
}
}
} else {
/** @var \yii\db\ActiveRecord $models */
if (!$models->validate(null, $clearErrors)) {
$isValid = false;
$this->addError($name, $models->getErrors());
}
}
}
return $isValid;
}
示例10: AssignToModelFromGrid
/**
* Присваивает выбранное значение из справочника модели, в сессии.
* При выборе значения из справочника, значение присваивается в сессию предыдущей хлебной крошки, для формы, с которой был открыт справочник.
* @param bool $RedirectPreviousUrl
* @param ActiveRecord $ActiveRecord Модель к которой присваивается знаечния из справочника.
* @param string $AttributeForeignID Имя атрибута
* @return string
*/
public static function AssignToModelFromGrid($RedirectPreviousUrl = True, $ActiveRecord = NULL, $AttributeForeignID = NULL)
{
if (Yii::$app->request->isAjax) {
$LastBC = Proc::GetLastBreadcrumbsFromSession();
$assigndata = filter_input(INPUT_POST, 'assigndata');
$foreign = isset($LastBC['dopparams']['foreign']) ? $LastBC['dopparams']['foreign'] : '';
if (!empty($foreign) && !empty($assigndata)) {
$BC = Proc::GetBreadcrumbsFromSession();
end($BC);
prev($BC);
$BC[key($BC)]['dopparams'][$foreign['model']][$foreign['field']] = $assigndata;
$session = new Session();
$session->open();
$session['breadcrumbs'] = $BC;
$session->close();
if ($ActiveRecord instanceof ActiveRecord && is_string($AttributeForeignID)) {
$field = $LastBC['dopparams']['foreign']['field'];
if ($ActiveRecord->formName() === $LastBC['dopparams']['foreign']['model']) {
$ActiveRecord->{$field} = $assigndata;
$ActiveRecord->{$AttributeForeignID} = $foreign['id'];
if ($ActiveRecord->validate()) {
$ActiveRecord->save(false);
}
}
}
if ($RedirectPreviousUrl) {
Yii::$app->response->redirect(Proc::GetPreviousURLBreadcrumbsFromSession());
}
} else {
return 'error foreign or assigndata empty AssignToModelFromGrid()';
}
}
}
示例11: validate
public function validate($attributeNames = null, $clearErrors = true)
{
foreach ($this->getRelatedRecords() as $relationName => $relatedRecord) {
$relation = $this->getRelation($relationName);
if ($relation->multiple) {
if (empty($relatedRecord)) {
continue;
}
/** @var Model[] $relatedRecord */
$attributes = $relatedRecord[0]->getAttributes();
foreach ($relation->link as $key => $value) {
unset($attributes[$key]);
}
if (!$this->validateMultiple($relatedRecord, $attributes)) {
foreach ($relatedRecord as $related) {
$this->addError($relationName, $related->getErrors());
}
return false;
}
} else {
if (!$relatedRecord instanceof Model) {
continue;
}
/** @var Model $relatedRecord */
if (!$relatedRecord->validate()) {
$this->addError($relationName, $relatedRecord->getErrors());
return false;
}
}
}
return parent::validate($attributeNames, $clearErrors);
}