Hi Maurizio, I know that this topic is very old, but I’m here because I had the same error.
But check this.
I used Gii to generate my views. I didn’t made any change in the files, when I test, Yii return this error
==> /var/log/apache2/error.log <==
[Thu Sep 29 14:25:30.585912 2016] [:error] [pid 16722] [client 127.0.0.1:46732] PHP Fatal error: Using $this when not in object context in /var/www/html/historia_clinica/backend/web/provincia/index.php on line 12
==> /var/log/apache2/other_vhosts_access.log <==
backend.dev:80 127.0.0.1 - - [29/Sep/2016:14:25:30 -0300] "GET /provincia/ HTTP/1.1" 500 185 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:48.0) Gecko/20100101 Firefox/48.0"
view/index.php
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\web\View;
/* @var $this yii\web\View */
/* @var $searchModel backend\controllers\provinciaSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Provincias';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="provincia-index">
<h1><?= $this->title ?></h1>
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a('Create Provincia', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php Pjax::begin(); ?> <?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'idprovincia',
'nombre',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<?php Pjax::end(); ?></div>
controller.php
<?php
namespace backend\controllers;
use Yii;
use backend\models\Provincia;
use backend\controllers\provinciaSearch;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\Controller;
/**
* ProvinciaController implements the CRUD actions for Provincia model.
*/
class ProvinciaController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Provincia models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new provinciaSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
I check the others files views to check how to work, and the structure is the same. In the view has the same variable "$this"…
I don’t understand why isn’t works my view. I have PHP 7.0.8.
I’ll appreciate your help with this