0

我在弄清楚如何使用 Yii2 堆栈跟踪来诊断问题时遇到了很多麻烦。具体来说,根据跟踪告诉我的内容,我很少能找到问题的根源(在我的代码中)。我敢肯定这只是我迟钝,所以我希望有人可以帮助我。例如,我突然遇到“PHP 警告 – yii\base\ErrorException call_user_func() 期望参数 1 是有效回调,未找到类 'error'”错误,我得到了下面的跟踪信息。我在跟踪列表中找不到任何可以指出我在编码中可能做错了什么的东西。一切似乎都指向核心编码,而不是我的。有人能帮我一下吗?

 PHP Warning – yii\base\ErrorException

call_user_func() 期望参数 1 是有效的回调,未找到类“错误”

1. in L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\BaseYii.php at line 346
337338339340341342343344345346347348349350351352353354355

    public static function createObject($type, array $params = [])
    {
        if (is_string($type)) {
            return static::$container->get($type, $params);
        } elseif (is_array($type) && isset($type['class'])) {
            $class = $type['class'];
            unset($type['class']);
            return static::$container->get($class, $params, $type);
        } elseif (is_callable($type, true)) {
            return call_user_func($type, $params);
        } elseif (is_array($type)) {
            throw new InvalidConfigException('Object configuration must be an array containing a "class" element.');
        } else {
            throw new InvalidConfigException("Unsupported configuration type: " . gettype($type));
        }
    }

    private static $_logger;


2. yii\base\ErrorHandler::handleError(2, 'call_user_func() expects paramet...', 'L:\xampp\htdocs\public_html\vend...', 346, ...)
3. in L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\BaseYii.php – call_user_func(['error', 'warning'], []) at line 346
4. in L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\log\Dispatcher.php – yii\BaseYii::createObject(['error', 'warning']) at line 101
5. in L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\base\Object.php – yii\log\Dispatcher::init() at line 107
6. in L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\log\Dispatcher.php – yii\base\Object::__construct(['traceLevel' => 3, 'targets' => ['class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning']]]) at line 89
7. yii\log\Dispatcher::__construct(['traceLevel' => 3, 'targets' => ['class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning']]])
8. in L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\di\Container.php – ReflectionClass::newInstanceArgs([['traceLevel' => 3, 'targets' => ['class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning']]]]) at line 368
9. in L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\di\Container.php – yii\di\Container::build('yii\log\Dispatcher', [], ['traceLevel' => 3, 'targets' => ['class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning']]]) at line 147
10. in L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\BaseYii.php – yii\di\Container::get('yii\log\Dispatcher', [], ['traceLevel' => 3, 'targets' => ['class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning']]]) at line 344
11. in L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\di\ServiceLocator.php – yii\BaseYii::createObject(['traceLevel' => 3, 'targets' => ['class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning']], 'class' => 'yii\log\Dispatcher']) at line 133
12. in L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\base\Application.php – yii\di\ServiceLocator::get('log') at line 302
13. in L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\web\Application.php – yii\base\Application::bootstrap() at line 63
14. in L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\base\Application.php – yii\web\Application::bootstrap() at line 267
15. in L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\base\Object.php – yii\base\Application::init() at line 107
16. in L:\xampp\htdocs\public_html\vendor\yiisoft\yii2\base\Application.php – yii\base\Object::__construct(['components' => ['cache' => ['class' => 'yii\caching\FileCache'], 'urlManager' => ['enablePrettyUrl' => true, 'showScriptName' => 'false', 'class' => 'yii\web\UrlManager', 'rules' => ['<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', '<controller:\w+>/<action:\w+>' => '<controller>/<action>']], 'db' => ['class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=larr...', 'username' => 'xxxx', 'password' => 'xxxx', ...], 'mailer' => ['class' => 'yii\swiftmailer\Mailer', 'viewPath' => '@common/mail', 'useFileTransport' => true], ...], 'modules' => ['social' => ['class' => 'kartik\social\Module', 'disqus' => ['settings' => ['shortname' => 'DISQUS_SHORTNAME']], 'facebook' => ['appId' => 'xxxxx', 'secret' => 'xxxxx']], 'gridview' => ['class' => '\kartik\grid\Module'], 'debug' => 'yii\debug\Module', 'gii' => 'yii\gii\Module'], 'id' => 'app-frontend', 'name' => 'MemeHope', ...]) at line 206
17. in L:\xampp\htdocs\public_html\frontend\web\index.php – yii\base\Application::__construct(['vendorPath' => 'L:\xampp\htdocs\public_html/vend...', 'components' => ['cache' => ['class' => 'yii\caching\FileCache'], 'urlManager' => ['enablePrettyUrl' => true, 'showScriptName' => 'false', 'class' => 'yii\web\UrlManager', 'rules' => ['<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', '<controller:\w+>/<action:\w+>' => '<controller>/<action>']], 'db' => ['class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=larr...', 'username' => 'xxxxx', 'password' => 'xxxxx', ...], 'mailer' => ['class' => 'yii\swiftmailer\Mailer', 'viewPath' => '@common/mail', 'useFileTransport' => true], ...], 'modules' => ['social' => ['class' => 'kartik\social\Module', 'disqus' => ['settings' => ['shortname' => 'DISQUS_SHORTNAME']], 'facebook' => ['appId' => 'xxxxxx', 'secret' => 'xxxx']], 'gridview' => ['class' => '\kartik\grid\Module'], 'debug' => 'yii\debug\Module', 'gii' => 'yii\gii\Module'], 'id' => 'app-frontend', ...]) at line 17
1112131415161718

    require(__DIR__ . '/../../common/config/main.php'),
    require(__DIR__ . '/../../common/config/main-local.php'),
    require(__DIR__ . '/../config/main.php'),
    require(__DIR__ . '/../config/main-local.php')
);

$application = new yii\web\Application($config);
$application->run();

这是 frontend/config/main.php 的样子:

<?php

$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'), require(__DIR__ . '/params-local.php')
);

return [
    'id'                  => 'app-frontend',
    'basePath'            => dirname(__DIR__),
    'name'                => 'MemeHope',
    'bootstrap'           => ['log'],
    'controllerNamespace' => 'frontend\controllers',
    'components'          => [

        'urlManager'   => [
            'class'           => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName'  => 'false',
            'rules'           => [
                '<controller:\w+>/<id:\d+>'              => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>'          => '<controller>/<action>',
            ],
        ],
        'log'          => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets'    => [
                'class'  => 'yii\log\FileTarget',
                'levels' => ['error', 'warning'],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'user'         => [
            'identityClass'   => 'common\models\User',
            'enableAutoLogin' => true,
        ],
    ],
    'modules'             => [
        'gridview' => [
            'class' => '\kartik\grid\Module'
            // enter optional module parameters below - only if you need to
            // use your own export download action or custom translation
            // message source
            // 'downloadAction' => 'gridview/export/download',
            // 'i18n' => []
        ],
    ],
    'params'              => $params,
];

其他所有内容都在 common/config/main.php 中,并且站点的后端运行良好,所以我怀疑问题是否存在。

4

1 回答 1

0

尝试通过运行composer update或更新您的项目php composer.phar update。有时文件在处理localhost. 它发生在我身上很多次。但是更新软件包解决了我的问题。看看,如果它也适合你。

于 2015-01-30T19:17:58.740 回答