本文整理汇总了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;
}
示例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];
}
示例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.'));
}
示例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.');
}
}
示例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]);
}