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


PHP base\Model类代码示例

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


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

示例1: __construct

 /**
  * @param Model $model
  * @param string $message
  * @param int $code
  * @param Exception $previous
  */
 public function __construct(Model $model, $message = null, $code = 0, Exception $previous = null)
 {
     $this->model = $model;
     if (is_null($message) && $model->hasErrors()) {
         $message = implode(' ', array_map(function ($errors) {
             return implode(' ', $errors);
         }, $model->getErrors()));
     }
     parent::__construct($message, $code, $previous);
 }
开发者ID:ivan-chkv,项目名称:yii2-boost,代码行数:16,代码来源:InvalidModelException.php

示例2: performValidationModel

 /**
  * Performs ajax validation.
  *
  * @param \yii\base\Model $model
  *
  * @throws \yii\base\ExitException
  */
 protected function performValidationModel(Model $model)
 {
     if ($model->load(Yii::$app->request->post())) {
         return ActiveForm::validate($model);
     }
     return;
 }
开发者ID:ostashevdv,项目名称:brick,代码行数:14,代码来源:AjaxValidation.php

示例3: performAjaxValidation

 /**
  * Performs ajax validation.
  * @param Model $model
  * @throws \yii\base\ExitException
  */
 protected function performAjaxValidation(Model $model)
 {
     if (\Yii::$app->request->isAjax && $model->load(\Yii::$app->request->post())) {
         \Yii::$app->response->format = Response::FORMAT_JSON;
         echo json_encode(ActiveForm::validate($model));
         \Yii::$app->end();
     }
 }
开发者ID:softal,项目名称:yii-user,代码行数:13,代码来源:RecoveryController.php

示例4: onLoad

 /**
  * Берет значения из POST и возвраает знаяения для добавления в БД
  *
  * @param array           $field
  * @param \yii\base\Model $model
  *
  * @return array
  */
 public static function onLoad($field, $model)
 {
     $fieldName = $field[BaseForm::POS_DB_NAME];
     $value = ArrayHelper::getValue(\Yii::$app->request->post(), $model->formName() . '.' . $fieldName, false);
     if ($value) {
         $value = true;
     }
     $model->{$fieldName} = $value;
 }
开发者ID:CAPITALOV,项目名称:capitalov,代码行数:17,代码来源:CheckBox.php

示例5: validateAttribute

 /**
  * server validatiom for unique zip_code
  * @param \yii\base\Model $model
  * @param string $attribute
  */
 public function validateAttribute($model, $attribute)
 {
     $value = $model->{$attribute};
     if (!Locations::find()->where(['zip_code' => $value])->exists()) {
         $model->addError($attribute, $this->message);
     }
 }
开发者ID:sydorenkovd,项目名称:yiiadv,代码行数:12,代码来源:ZipcodeValidator.php

示例6: modelErrors

 public static function modelErrors(Model $model, $message = null, $category = 'application')
 {
     if (!is_null($message)) {
         static::error($message, $category);
     }
     if ($model->hasErrors()) {
         static::error(['class' => get_class($model), 'attributes' => $model->getAttributes(), 'errors' => $model->getErrors()], $category);
     }
 }
开发者ID:ivan-chkv,项目名称:yii2-kladovka,代码行数:9,代码来源:Log.php

示例7: load

 /**
  * Populates the model with input data.
  * @param Model $model model instance.
  * @param array $data the data array to load, typically `$_POST` or `$_GET`.
  * @return boolean whether expected forms are found in `$data`.
  */
 protected function load($model, $data)
 {
     /* @var $this Action */
     $event = new ActionEvent($this, ['model' => $model, 'result' => $model->load($data)]);
     $this->trigger('afterDataLoad', $event);
     return $event->result;
 }
开发者ID:yii2tech,项目名称:admin,代码行数:13,代码来源:ModelFormTrait.php

示例8: getHotlinkTo

 public function getHotlinkTo(Model $model, $action = null, $options = [])
 {
     if (!ArrayHelper::isIn($this->className(), ArrayHelper::getColumn($model->behaviors(), 'class'))) {
         throw new InvalidRouteException('The "LinkableBehavior" is not attached to the specified model');
     }
     return $this->getHotlink(strtr('{route}/{action}', ['{route}' => $model->route, '{action}' => $action ?? $model->defaultAction]), $model->linkableParams, $options);
 }
开发者ID:weblement,项目名称:yii2,代码行数:7,代码来源:LinkableBehavior.php

示例9: getIndexGridColumns

 /**
  * Retrieves grid columns configuration using the modelClass.
  * @param Model $model
  * @param array $fields
  * @return array grid columns
  */
 public function getIndexGridColumns($model, $fields)
 {
     $id = Yii::$app->request->getQueryParam('id');
     $relationName = Yii::$app->request->getQueryParam('relation');
     $multiple = Yii::$app->request->getQueryParam('multiple', 'true') === 'true';
     foreach ($fields as $key => $field) {
         if ((is_array($field) || !is_string($field) && is_callable($field)) && $key === $relationName || $field === $relationName) {
             unset($fields[$key]);
         }
     }
     return array_merge([['class' => 'yii\\grid\\CheckboxColumn', 'multiple' => $multiple, 'headerOptions' => ['class' => 'column-serial'], 'checkboxOptions' => function ($model, $key, $index, $column) use($id, $relationName) {
         /** @var \yii\db\ActiveRecord $model */
         $options = ['value' => is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : $key];
         if (empty($relationName) || $model->{$relationName} === null || trim($id) === '') {
             return $options;
         }
         $relation = $model->getRelation($relationName);
         if ($relation->multiple) {
             /** @var \yii\db\ActiveRecord $relationClass */
             $relationClass = $relation->modelClass;
             if (Action::importKey($relationClass::primaryKey(), $id) === $model->getAttributes(array_keys($relation->link))) {
                 $options['checked'] = true;
                 $options['disabled'] = true;
             }
         } elseif (Action::exportKey($relation->one()->getPrimaryKey()) === $id) {
             $options['checked'] = true;
             $options['disabled'] = true;
         }
         return $options;
     }], ['class' => 'yii\\grid\\SerialColumn', 'headerOptions' => ['class' => 'column-serial']]], self::getGridColumns($model, $fields));
 }
开发者ID:netis-pl,项目名称:yii2-crud,代码行数:37,代码来源:RelationAction.php

示例10: serializeModelErrors

 /**
  * Serializes the validation errors in a model.
  * @param Model $model
  * @return array the array representation of the errors
  */
 protected function serializeModelErrors($model)
 {
     Yii::$app->response->setStatusCode(422, 'Data Validation Failed.');
     $result = [];
     foreach ($model->getFirstErrors() as $name => $message) {
         $result[] = ['field' => $name, 'message' => $message];
     }
     return $result;
 }
开发者ID:dextercool,项目名称:yii2-easyui,代码行数:14,代码来源:Serializer.php

示例11: checkRequiredParams

 public static function checkRequiredParams($params, $required_params)
 {
     $missing_parameters = self::allTheRequiredParametersAre($params, $required_params);
     $model = new Model();
     if ($missing_parameters) {
         $model->addError("this parameters are missing ", $error = implode(", ", $missing_parameters));
     }
     return $model;
 }
开发者ID:avrahamichler,项目名称:Highnet,代码行数:9,代码来源:ApiParams.php

示例12: set

 /**
  * @inheritdoc
  */
 public function set(Model $model)
 {
     if (Yii::$app->user->getIsGuest()) {
         return;
     }
     $data = $model->toArray();
     $this->getStorage()->setBounded('theme', $data);
     $this->setToCache($data);
 }
开发者ID:hiqdev,项目名称:hipanel-core,代码行数:12,代码来源:ThemeSettingsStorage.php

示例13: prepareMessages

 /**
  * Applies the required formatting and params to messages.
  * @param Model $model
  * @param string $attribute
  * @return array Prepared messages
  */
 public function prepareMessages($model, $attribute)
 {
     $params = array_merge($this->messageParams(), ['attribute' => $model->getAttributeLabel($attribute)]);
     $messages = [];
     foreach ($this->messages() as $name => $message) {
         $messages[$name] = Yii::$app->getI18n()->format($message, $params, Yii::$app->language);
     }
     return $messages;
 }
开发者ID:undefinedstudio,项目名称:yii2-angular-form,代码行数:15,代码来源:AngularValidator.php

示例14: errorsToString

 /**
  * Extracts Model errors from array and puts them into string
  * @param Model $model
  * @param boolean $html
  * @return string
  */
 public static function errorsToString($model, $html = true)
 {
     $result = '';
     $delimiter = $html ? "<br/>\n" : "\n";
     foreach ($model->errors as $attribute => $error) {
         $errors = implode(', ', $error);
         $result .= $model->getAttributeLabel($attribute) . ": {$errors}{$delimiter}";
     }
     return $result;
 }
开发者ID:sjoorm,项目名称:yii2-components,代码行数:16,代码来源:Misc.php

示例15: getModelDirectory

 /**
  * @param \yii\base\Model $model
  *
  * @return string
  */
 public function getModelDirectory(Model $model)
 {
     if (!$model->canGetProperty('idAttribute')) {
         throw new \LogicException("Model {$model->className()} has not 'idAttribute' property");
     }
     $modelName = $this->getShortClass($model);
     /** @noinspection PhpUndefinedFieldInspection */
     $modelId = $model->{$model->idAttribute};
     return $this->_getSubDirectory($modelName, $modelId);
 }
开发者ID:romka-chev,项目名称:yii2-images-module,代码行数:15,代码来源:ImagesModule.php


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