Passed
Push — master ( 026f9b...4b240a )
by Aleksandr
02:50
created

ViewAction::run()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 3
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
        $id = \Yii::$app->request->get($this->primaryKeyParam);
25
        $model = $this->controller->findModel($id, $this->controller->viewClass);
26
27
        if ($this->updateIfPost && Yii::$app->request->isPost) {
28
            return $this->controller->runAction($this->updateAction, [$this->primaryKeyParam => $id]);
29
        }
30
        return $this->controller->render($this->view, ['model' => $model]);
31
    }
32
}