1
votes

I am trying to render a view via an Action but yii2 throws an error at me. I have tried debugging it but I have not found anything. here is my code: The controller:

<?php

namespace app\controllers;

use yii\web\Controller;

class CalculatorController extends Controller
{
    public function actions()
    {
        return [
            'show' => 'app\controllers\frontend\calculator\ShowAction',
        ];
    }
}

The action:

<?php

namespace app\controllers\frontend\calculator;

use yii\base\Action;

class ShowAction extends Action
{
    public function run()
    {
        return $this->controller->render('frontend/calculator/show');
    }
}

the view:

<?php

namespace app\controllers\frontend\calculator;

use yii\base\Action;

class ShowAction extends Action
{
    public function run()
    {
        return $this->controller->render('frontend/calculator/show');
    }
}

The error:

View not Found – yii\base\ViewNotFoundException The view file does not exist: C:\xampp\htdocs\basic\views\calculator\frontend/calculator/show.php

But the correct path to the view would be:

C:\xampp\htdocs\basic\views\frontend/calculator/show.php

I have no idea where the extra "calculator" came from. thank you in advance!

EDIT: so if I type ../ before the view path it is working. but I stil want to know why this weird stuff is happening...

1
Could you clarify what you are trying to do here, please? Your code doesn't resemble a standard Yii2 MVC pattern. Also, in your path, you have both "basic" and "frontend", which sounds like you may be trying to work with some kind of hybrid between the basic and advanced templates? - Rich Harding

1 Answers

1
votes

'frontend/calculator/show' is the relative path so it will be searched under current controller.
Your additional 'calculator' part is the controller name.