本文整理汇总了PHP中common\models\Option::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Option::find方法的具体用法?PHP Option::find怎么用?PHP Option::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\Option
的用法示例。
在下文中一共展示了Option::find方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getOptions
/**
* 获取网站配置数组
* @return array
*/
public static function getOptions()
{
if (self::$_options == null) {
$options = \common\models\Option::find()->asArray()->all();
self::$_options = yii\helpers\ArrayHelper::map($options, 'name', 'value');
}
return self::$_options;
}
示例2: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
* @return ActiveDataProvider
*/
public function search($params)
{
$query = OptionModel::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id]);
$query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'value', $this->value])->andFilterWhere(['like', 'label', $this->label])->andFilterWhere(['like', 'group', $this->group]);
return $dataProvider;
}
示例3: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = OptionModel::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id]);
$query->andFilterWhere(['like', 'option_name', $this->option_name])->andFilterWhere(['like', 'option_value', $this->option_value])->andFilterWhere(['like', 'option_label', $this->option_label])->andFilterWhere(['like', 'option_group', $this->option_group]);
return $dataProvider;
}
示例4: getAll
/**
* @param null $template_id
* @return array
*/
public static function getAll($template_id = null)
{
$options = [];
if ($template_id) {
$model = Option::find()->where(['template_id' => $template_id])->all();
} else {
$model = Option::find()->all();
}
if ($model) {
foreach ($model as $m) {
$options[$m->id] = $m->name;
}
}
return $options;
}
示例5: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$this->scenario = 'search';
$query = Option::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id, 'template_id' => $this->template_id, 'multiple' => $this->multiple, 'require' => $this->require, 'type' => $this->type]);
$query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'name', $this->name]);
return $dataProvider;
}
示例6: getOptions
/**
* @return array|\yii\db\ActiveRecord[]
*/
public function getOptions()
{
$options = Option::find()->where(['template_id' => $this->template_id])->orderBy('id')->all();
return $options;
}
示例7: findModelByGroup
/**
* Finds the Option models based on their group.
* If the models are not found, a 404 HTTP exception will be thrown.
*
* @param string $id
*
* @return Option the loaded model
* @throws NotFoundHttpException if the models cannot be found
*/
protected function findModelByGroup($id)
{
if ($model = Option::find()->where(['option_group' => $id])->indexBy('option_name')->all()) {
return $model;
}
throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
}
示例8: actionGroup
/**
* Render option page for specific group of option.
* It will use group file if exist.
*
* @param string $id group name
*
* @return string|\yii\web\Response
* @throws \yii\web\NotFoundHttpException
*/
public function actionGroup($id)
{
$model = Option::find()->where(['option_group' => $id])->indexBy('option_name')->all();
if ($options = Yii::$app->request->post('Option')) {
foreach ($options as $option_name => $option) {
Option::up($option_name, $option['option_value']);
}
Yii::$app->getSession()->setFlash('success', Yii::t('writesdown', 'Settings successfully saved.'));
return $this->redirect(['group', 'id' => $id]);
}
if ($model) {
if (is_file($viewFile = $this->getViewPath() . '/' . strtolower($id) . '.php')) {
return $this->render(strtolower($id), ['model' => (object) $model, 'group' => $id]);
} else {
return $this->redirect(['index']);
}
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}