0

I want to create a new class that extend from yii2 Kartik gridview

namespace mywidget\grid;

use kartik\base\Config;
use kartik\dialog\Dialog;
use kartik\mpdf\Pdf;
use Yii;
use yii\base\InvalidConfigException;
use yii\bootstrap\ButtonDropdown;
use yii\grid\Column;
use kartik\grid\GridView as YiiGridView;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\helpers\Url;
use yii\web\JsExpression;
use yii\web\View;
use yii\widgets\Pjax;
class GridView extends YiiGridView
{

}

the problem is when i call grid view , an error exception is thrown : Class not found. So i wonder if it'is the right way to extend from a widget class ??

soussou
  • 41
  • 6

2 Answers2

1

The namespace you have used is not registered.

The simpliest solution is to change the namespace to one of the registered with Yii 2.

  • for Basic Project it's app - so if you the path to your extended class is mywidget/grid/GridView.php namespace is app\mywidget\grid
  • for Advanced Project it's common, frontend or backend so depending on the one you choose place folder there and replace app accordingly

If you insist on using mywidget\grid namespace you have to register it first. Read more about this in the Guide: Class Autoloading

Bizley
  • 17,392
  • 5
  • 49
  • 59
  • i change it to common\widgets and i put the namespace : namespace common\widgets; and after this i put : use common\widgets\grid\GridView in my view file. But same error – soussou Jan 05 '17 at 11:17
  • 1
    You have set different namespace than you call. It's `namespace common\widgets;` and then `use common\widgets\GridView;` **OR** `namespace common\widgets\grid;` and then `use common\widgets\grid\GridView;` (class must be in one additional folder `grid` as well). – Bizley Jan 05 '17 at 14:04
0

the exception is about my class which is not found : use mywidget\grid\GridView

it sounds like it's an autoloading issue, make sure the file you're working in has the same path in your project as the namespace you're using. in this case should be mywidget\grid\GridView.php or adjust your namespace to match your file location

.. if that's not the case please provide more details about the error you're receiving and use case of your class

csminb
  • 2,382
  • 1
  • 16
  • 27