Как исправить ошибку от Yii2: Not instantiable – yii\di\NotInstantiableException Failed to instantiate component or class "yii\grid\.."
При замене оригинального класса дочерним получаю сообщение об ошибке:
Not instantiable – yii\di\NotInstantiableException
Failed to instantiate component or class "yii\grid\MyActionColumn".
Caused by: ReflectionException
Class "yii\grid\MyActionColumn" does not exist
Cтрочки кода из views/contact/index.php, которые вызывают ошибку:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'emptyText' => 'По указанным параметрам сотрудник не найден.',
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'last_name',
'first_name',
'middle_name',
'internal_phone',
'mobile_phone',
'email_address:email',
['class' => 'yii\grid\MyActionColumn',
'template' => '{view} {update} {delete}',
],
],
]); ?>
controllers/MyActionColumn.php:
<?php
namespace yii\grid;
use Yii;
class MyActionColumn extends ActionColumn
{
}
composer.json:
{
"name": "yiisoft/yii2-app-basic",
"description": "Yii 2 Basic Project Template",
"keywords": ["yii2", "framework", "basic", "project template"],
"homepage": "http://www.yiiframework.com/",
"type": "project",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"minimum-stability": "stable",
"require": {
"php": ">=5.6.0",
"yiisoft/yii2": "~2.0.14",
"yiisoft/yii2-bootstrap4": "~2.0.0",
"yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.1.0",
"yiisoft/yii2-gii": "~2.2.0",
"yiisoft/yii2-faker": "~2.0.0",
"codeception/codeception": "^4.0",
"codeception/verify": "~0.5.0 || ~1.1.0",
"codeception/specify": "~0.4.6",
"symfony/browser-kit": ">=2.7 <=4.2.4",
"codeception/module-filesystem": "^1.0.0",
"codeception/module-yii2": "^1.0.0",
"codeception/module-asserts": "^1.0.0"
},
"config": {
"process-timeout": 1800,
"fxp-asset": {
"enabled": false
}
},
"scripts": {
"post-install-cmd": [
"yii\\composer\\Installer::postInstall"
],
"post-create-project-cmd": [
"yii\\composer\\Installer::postCreateProject",
"yii\\composer\\Installer::postInstall"
]
},
"extra": {
"yii\\composer\\Installer::postCreateProject": {
"setPermission": [
{
"runtime": "0777",
"web/assets": "0777",
"yii": "0755"
}
]
},
"yii\\composer\\Installer::postInstall": {
"generateCookieValidationKey": [
"config/web.php"
]
}
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
}
в чем может быть дело?
Ответы (1 шт):
Автор решения: Simply One
→ Ссылка
проблема решилась перемещением файла MyActionColumn.php во вновь созданную папку components, изменением пути в views/contact/index.php:
'class' => 'app\components\MyActionColumn',
и заменой строчки в MyActionColumn.php на:
namespace app\components;