无法在我的 yii2 项目中查看高图表

问题描述 投票:0回答:1

我已经在我的项目中安装了

highcharts
包。现在我尝试查看示例图表,但出现错误。

use miloschuman\highcharts\Highcharts;
 <?=
  Highcharts::widget([
      'options' => [
          'title' => ['text' => 'Fruit Consumption'],
          'xAxis' => [
              'categories' => ['Apples', 'Bananas', 'Oranges']
          ],
          'yAxis' => [
              'title' => ['text' => 'Fruit eaten']
          ],
          'series' => [
              ['name' => 'Jane', 'data' => [1, 0, 4]],
              ['name' => 'John', 'data' => [5, 7, 3]]
          ]
      ]
  ]);
  ?>

错误

Invalid Argument – yii\base\InvalidArgumentException

要发布的文件或目录不存在:F:\xampp\htdocs\mdc/vendorower/highcharts

更新1

下面是我的堆栈跟踪

enter image description here

更新2

下面是我的

composer.json

{
"name": "yiisoft/yii2-app-advanced",
"description": "Yii 2 Advanced Project Template",
"keywords": ["yii2", "framework", "advanced", "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": "dev",
"require": {
    "php": ">=5.4.0",
    "yiisoft/yii2": "~2.0.13",
    "yiisoft/yii2-bootstrap": "~2.0.0",
    "yiisoft/yii2-swiftmailer": "~2.0.0",
    "luoxiaojun1992/yii2-tinker": "*",
    "kartik-v/yii2-grid": "@dev",
    "kartik-v/yii2-widget-select2": "@dev",
    "kartik-v/yii2-mpdf": "dev-master",
    "moonlandsoft/yii2-phpexcel": "*",
    "nirvana-msu/yii2-showloading": "1.0.*@dev",
    "kartik-v/yii2-krajee-base": "^2.0",
    "kartik-v/yii2-widget-spinner": "@dev",
    "edwinhaq/yii2-simple-loading": "*",
    "c006/yii2-submit-spinner": "*",
    "kartik-v/yii2-detail-view": "*",
    "fedemotta/yii2-cronjob": "*",
    "kartik-v/yii2-widget-datetimepicker": "*",
    "kartik-v/yii2-date-range": "dev-master",
    "phpoffice/phpspreadsheet": "^1.2",
    "linslin/yii2-curl": "*",
    "kartik-v/yii2-widget-fileinput": "@dev",
    "kartik-v/yii2-dialog": "*",
    "google/apiclient": "^2.0",
    "delight-im/str": "^2.4",
    "mongosoft/yii2-soap-client": "dev-master",
    "kartik-v/yii2-export": "@dev",
    "ext-json": "*",
    "miloschuman/yii2-highcharts-widget": "*",
    "simialbi/yii2-widget-chart": "^1.0@dev",
    "onmotion/yii2-widget-apexcharts": "dev-master",
    "2amigos/yii2-chartjs-widget": "~2.0",
    "kartik-v/yii2-bootstrap4-dropdown": "@dev",
    "practically/yii2-chartjs": "dev-master",
    "php-parallel-lint/php-console-color": "dev-master",
    "nnnick/chartjs": "v2.9.3"
},
"require-dev": {
    "yiisoft/yii2-debug": "~2.0.0",
    "yiisoft/yii2-gii": "~2.0.0",
    "yiisoft/yii2-faker": "~2.0.0",

    "codeception/base": "^2.2.3",
    "codeception/verify": "~0.3.1"
},

"config": {
    "process-timeout": 1800,
    "fxp-asset": {
        "enabled": false
    }
},
"extra": {
    "asset-installer-paths": {
        "npm-asset-library": "vendor/npm",
        "bower-asset-library": "vendor/bower"
    }
},
"scripts": {
    "post-install-cmd": "php init --env=Development --overwrite=n"
},
"autoload": {
    "psr-4": {
        "kartik\\spinner\\": "",
        "nirvana\\showloading\\": ""
    }
},
"repositories": [{
    "type": "composer",
    "url": "https://asset-packagist.org"
}]
}

更新3

highcharts
中删除了
composer.json
包,然后执行
composer update

F:\xampp\htdocs\mdc>composer require --prefer-dist miloschuman/yii2-highcharts-widget "*"
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
- Installing bower-asset/highcharts (v7.2.1): Loading from cache
- Installing miloschuman/yii2-highcharts-widget (dev-master 260b946): Loading from cache
Package codeception/base is abandoned, you should avoid using it. No replacement was suggested.
Package jakub-onderka/php-console-color is abandoned, you should avoid using it. Use php-parallel-lint/php-console-color instead.
Package jakub-onderka/php-console-highlighter is abandoned, you should avoid using it. Use php-parallel-lint/php-console-highlighter instead.
Writing lock file
Generating autoload files
14 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

出现同样的错误

无效参数 – yii ase\InvalidArgumentException

The file or directory to be published does not exist: F:\xampp\htdocs\mdc/vendor\bower/highcharts

更新4

根据@Taron 第一个解决方案,我有

backend/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')
// require(__DIR__ .'/main-local.php')
);

 return [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'bootstrap' => ['log'],
'modules' => [
    'gridview' => [
        'class' => '\kartik\grid\Module'
    ],
    'api' => [
'class' => 'backend\modules\api\Api',
       ],  
],

 'timeZone' => 'Asia/Karachi',

'components' => [
    'request' => [
        'csrfParam' => '_csrf-backend',
        'parsers' => [
            'application/json' => 'yii\web\JsonParser',
        ],
        'enableCookieValidation' => false,
        'enableCsrfValidation' => false,
    ],
    'user' => [
        'identityClass' => 'common\models\User',
        'enableAutoLogin' => true,
        'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
    ],
    'session' => [
        // this is the name of the session cookie used for login on the backend
        'name' => 'advanced-backend',
    ],
    'log' => [
        'traceLevel' => YII_DEBUG ? 3 : 0,
        'targets' => [
            [
                'class' => 'yii\log\FileTarget',
                'levels' => ['error', 'warning'],
            ],
        ],
    ],
    'errorHandler' => [
        'errorAction' => 'site/error',
    ],
    'urlManager' => [
        'class' => 'yii\web\UrlManager',
        'showScriptName' => false,
        'enablePrettyUrl' => true,
        'rules' => array(
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
        ),
    ],
],
'params' => $params,
];

如何消除这个错误?

任何帮助将不胜感激

php highcharts yii2 composer-php bower
1个回答
0
投票

看起来像 Bower 资源存储在路径

/vendor/bower-assets
中,但您的脚本尝试从
vendor/bower
加载资源(Bower 资源路径错误)。尝试以下解决方案,我希望其中之一能帮助您。

先解决方案:

  1. 只需将以下别名添加到您的配置文件中(config/web.php

    'aliases' => [ 
        '@bower' => '@vendor/bower-asset', 
        '@npm'   => '@vendor/npm-asset', 
    ], 
    

解决方案二:

  1. 删除 composer.lock 文件
  2. 添加 fxp 包:
    composer globalrequire "fxp/composer-asset-plugin:~1.1.1"
  3. 重新安装作曲家:
    composer --prefer-dist install
© www.soinside.com 2019 - 2024. All rights reserved.