monster-hunter /
yii2-settings
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | namespace pheme\settings; |
||
| 3 | |||
| 4 | use Yii; |
||
| 5 | use yii\base\Action; |
||
| 6 | |||
| 7 | class SettingsAction extends Action |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var string class name of the model which will be used to validate the attributes. |
||
| 11 | * The class should have a scenario matching the `scenario` variable. |
||
| 12 | * The model class must implement [[Model]]. |
||
| 13 | * This property must be set. |
||
| 14 | */ |
||
| 15 | public $modelClass; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var string The scenario this model should use to make validation |
||
| 19 | */ |
||
| 20 | public $scenario; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var string the name of the view to generate the form. Defaults to 'settings'. |
||
| 24 | */ |
||
| 25 | public $viewName = 'settings'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Render the settings form. |
||
| 29 | */ |
||
| 30 | public function run() |
||
| 31 | { |
||
| 32 | /* @var $model \yii\db\ActiveRecord */ |
||
| 33 | $model = new $this->modelClass(); |
||
| 34 | if ($this->scenario) { |
||
| 35 | $model->setScenario($this->scenario); |
||
| 36 | } |
||
| 37 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
||
| 38 | foreach ($model->toArray() as $key => $value) { |
||
| 39 | Yii::$app->settings->set($key, $value, $model->formName()); |
||
| 40 | } |
||
| 41 | Yii::$app->getSession()->addFlash('success', |
||
|
0 ignored issues
–
show
|
|||
| 42 | Module::t('settings', 'Successfully saved settings on {section}', |
||
| 43 | ['section' => $model->formName()] |
||
| 44 | ) |
||
| 45 | ); |
||
| 46 | } |
||
| 47 | foreach ($model->attributes() as $key) { |
||
| 48 | $model->{$key} = Yii::$app->settings->get($key, $model->formName()); |
||
| 49 | } |
||
| 50 | return $this->controller->render($this->viewName, ['model' => $model]); |
||
| 51 | } |
||
| 52 | } |
||
| 53 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: