ViewAction::run()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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