ViewAction::run()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
eloc 4
c 4
b 1
f 0
dl 0
loc 7
rs 10
cc 4
nc 2
nop 0
1
<?php
2
3
4
namespace carono\yii2crud\actions;
5
6
7
use carono\yii2crud\CrudController;
8
use Yii;
9
10
/**
11
 * Class ViewAction
12
 *
13
 * @package app\actions
14
 * @property CrudController $controller
15
 */
16
class ViewAction extends Action
17
{
18
    public $view = 'view';
19
    public $updateIfPost = true;
20
    public $updateAction = 'update';
21
22
    public function run()
23
    {
24
        $model = $this->findModel($this->modelClass ?: $this->controller->viewClass);
25
        if ($this->updateIfPost && Yii::$app->request->isPost) {
26
            return $this->controller->runAction($this->updateAction, $this->params);
27
        }
28
        return $this->controller->render($this->view, ['model' => $model]);
29
    }
30
}