Reputation: 41
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 ??
Upvotes: 0
Views: 563
Reputation: 18021
The namespace you have used is not registered.
The simpliest solution is to change the namespace to one of the registered with Yii 2.
app
- so if you the path to your extended class is mywidget/grid/GridView.php
namespace is app\mywidget\grid
common
, frontend
or backend
so depending on the one you choose place folder there and replace app
accordinglyIf you insist on using mywidget\grid
namespace you have to register it first. Read more about this in the Guide: Class Autoloading
Upvotes: 1
Reputation: 2382
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
Upvotes: 0