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


PHP Option::findOne方法代码示例

本文整理汇总了PHP中common\models\Option::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Option::findOne方法的具体用法?PHP Option::findOne怎么用?PHP Option::findOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common\models\Option的用法示例。


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

示例1: beforeValidate

 /**
  * @return bool
  * Динамическая валидация
  * @TODO  Углубленная валидация списков (с проверкой наличия базы), изображений
  */
 public function beforeValidate()
 {
     /** @var \common\models\Option $option */
     $option = Option::findOne($this->option_id);
     if ($option) {
         switch ($option->type) {
             case 1:
                 //число целое
             //число целое
             case 4:
                 //выключатель
             //выключатель
             case 8:
                 //список дочерних документов
             //список дочерних документов
             case 9:
                 //список потомков документа
             //список потомков документа
             case 10:
                 //список пользователей
                 $this->validators[] = Validator::createValidator('integer', $this, 'value');
                 break;
             case 2:
                 //число
                 $this->validators[] = Validator::createValidator('double', $this, 'value');
                 break;
             case 3:
                 //строка
             //строка
             case 5:
                 //текст
             //текст
             case 6:
                 //файл (выбор)
                 $this->validators[] = Validator::createValidator('string', $this, 'value');
                 break;
             case 7:
                 //изображение (загрузка)
                 $this->validators[] = Validator::createValidator('image', $this, 'file', ['minHeight' => 100, 'skipOnEmpty' => true]);
                 break;
             case 11:
                 //регулярное выражение
                 $pattern = $option->param ? $option->param : '\\w';
                 $this->validators[] = Validator::createValidator('match', $this, 'value', ['pattern' => $pattern]);
                 break;
         }
         if ($option->require) {
             if ($option->type == 7) {
                 if (!$this->value) {
                     $this->validators[] = Validator::createValidator('required', $this, 'file');
                 }
             } else {
                 $this->validators[] = Validator::createValidator('required', $this, 'value');
             }
         }
     }
     return true;
 }
开发者ID:darkffh,项目名称:yii2-lowbase,代码行数:63,代码来源:Field.php

示例2: getRateLimit

 /**
  * Returns the maximum number of allowed requests and the window size.
  * @param \yii\web\Request $request the current request
  * @param \yii\base\Action $action the action to be executed
  * @return array an array of two elements. The first element is the maximum number of allowed requests,
  * and the second element is the size of the window in seconds.
  */
 public function getRateLimit($request, $action)
 {
     $allow = 10;
     $window = 600;
     $route = $action->controller->route;
     $rate_limit_name = Module::getApiName($route);
     $rate_limit_option = Option::findOne(['name' => $rate_limit_name]);
     if ($rate_limit_option) {
         try {
             $option = \yii\helpers\Json::decode($rate_limit_option->value);
             if (!array_key_exists('allow', $option) || !is_numeric($option['allow']) || !is_int($option['allow']) || $option['allow'] < 0 || $option['allow'] > Option::RATE_LIMIT_ALLOW_MAX) {
                 throw new \yii\base\InvalidParamException('Invalid allow value.');
             }
             if (!array_key_exists('window', $option) || !is_numeric($option['window']) || !is_int($option['window']) || $option['window'] < 0 || $option['allow'] > Option::RATE_LIMIT_WINDOW_MAX) {
                 throw new \yii\base\InvalidParamException('Invalid window value.');
             }
         } catch (\Exception $ex) {
             $option['allow'] = $allow;
             $option['window'] = $window;
         }
         return [$option['allow'], $option['window']];
     }
     return [$allow, $window];
 }
开发者ID:rhosocial,项目名称:rho.social,代码行数:31,代码来源:UserRateLimiter.php

示例3: findModel

 /**
  * Finds the Option model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return Option the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Option::findOne($id)) !== null) {
         return $model;
     }
     throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
 }
开发者ID:tampaphp,项目名称:app-cms,代码行数:16,代码来源:SettingController.php

示例4: findModel

 /**
  * Finds the Option model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return Option the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Option::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:ochiem,项目名称:app-cms,代码行数:17,代码来源:SettingController.php

示例5: actionAjaxoption

 /**
  * Отображение дополнительного поля
  * Используется при добавлении значения
  * мультиполя
  * @return mixed
  */
 public function actionAjaxoption()
 {
     $id = Yii::$app->request->post('id');
     $new_field = Yii::$app->request->post('newfield');
     $option = Option::findOne($id);
     return $this->renderAjax('_field', ['option' => $option, 'option_id' => $id, 'field_id' => 'multi_new_' . $new_field]);
 }
开发者ID:darkffh,项目名称:yii2-lowbase,代码行数:13,代码来源:DocumentController.php


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