當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。