Problem using $ this- Error: Using $ this when not in object- Yii2

0

I am currently using the framework yii2 , this one has a code generator called gii. When using the gii to generate the model, view and controller there is no problem, I create the 3 without problem, the real problem is when I want to see the result on the local server. The error that throws me is this:

  

Fatal error: Uncaught Error: Using $ this when not in object context in C: \ xampp \ htdocs \ basic \ views \ Computer \ index.php: 10 Stack trace: # 0 {main} thrown in C: \ xampp \ htdocs \ basic \ views \ Computer \ index.php on line 10

This is the action of my controller (IT IS CALLED "EquipoController"):

public function actionIndex()
{

    $searchModel = new EquipoSearch();
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
            return $this->render('index', [
        'searchModel' => $searchModel,
        'dataProvider' => $dataProvider,
    ]);
}

This is my view and where the error is generated:

<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel app\models\EquipoSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

 $this->title = 'Inventario'; //Esta es la linea 10
 $this->params['breadcrumbs'][] = $this->title;
 ?>

Please, I need help to know why the error occurs and how to solve it, thanks in advance.

    
asked by Mr.Manutri 25.04.2018 в 14:19
source

1 answer

1

You seem to be trying to open the view directly, using a link like http://localhost/app/views/equipo/index.php .
This is not the way to access the page, everything has to happen to the controller.

In addition, your application is accessible from a single point that is this http://localhost/app/web/index.php

From here you have to indicate which controller and action to use , so your link to access the action index of EquipoController must be this: http://localhost/app/web/index.php?r=equipo/index

    
answered by 25.04.2018 / 15:57
source