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 | * @var string name on section. Default is ModelClass formname |
||
29 | */ |
||
30 | public $section = null; |
||
31 | |||
32 | /** |
||
33 | * Render the settings form. |
||
34 | */ |
||
35 | public function run() |
||
36 | { |
||
37 | /* @var $model \yii\db\ActiveRecord */ |
||
38 | $model = new $this->modelClass(); |
||
39 | $section = ($this->section !== null) ? $this->section : $model->formName(); |
||
40 | if ($this->scenario) { |
||
41 | $model->setScenario($this->scenario); |
||
42 | } |
||
43 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
||
44 | foreach ($model->toArray() as $key => $value) { |
||
45 | Yii::$app->settings->set($key, $value, $section); |
||
46 | } |
||
47 | Yii::$app->getSession()->addFlash('success', |
||
0 ignored issues
–
show
|
|||
48 | Module::t('settings', 'Successfully saved settings on {section}', |
||
49 | ['section' => $model->formName()] |
||
50 | ) |
||
51 | ); |
||
52 | } |
||
53 | foreach ($model->attributes() as $key) { |
||
54 | $model->{$key} = Yii::$app->settings->get($key, $section); |
||
55 | } |
||
56 | return $this->controller->render($this->viewName, ['model' => $model]); |
||
57 | } |
||
58 | } |
||
59 |
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: