热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Yii2-Gii扩展资产文件夹别名,指向错误的路径。-Yii2-Giiextensionassetsfolderaliasreferencingtoawrongpath

IamtryingtolearnYii2fromabook(WebapplicationdevelopmentwithYii2andPHP).Somewhereal

I am trying to learn Yii 2 from a book (Web application development with Yii2 and PHP). Somewhere along the line it instructs me to install gii and create crud files with it.

我正在尝试从一本书中学习Yii2(使用Yii2和PHP开发Web应用程序)。在这一行的某个地方,它指示我安装gii并使用它创建crud文件。

When I installed with the following command:

当我安装了以下命令:

php composer.phar require --prefer-dist "yiisoft/yii2-gii:*"

I have following error:

我有以下错误:

Invalid Parameter – yii\base\InvalidParamException The file or directory to be published does not exist: /var/projectsRoot/crmapp/src/vendor/yiisoft/yii2/gii/assets

无效参数- yii\base\InvalidParamException将被发布的文件或目录不存在:/var/ projectsroot /crmapp/src/vendor/yiisoft/yii2/gii/资产。

My bootstrap code:

我的引导代码:

//Define Yii debug mode
define (YII_DEBUG, true);

//Including composer autoloader
require (__DIR__ . '/../vendor/autoload.php');

//Including Yii framework
require (__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

//debugging for PHP
ini_set('display_errors', true);

//Getting Configuration
$cOnfig= require(__DIR__ . '/../config/web.php');

//Include and launch application
(new yii\web\Application($config))->run();

config file:

配置文件:

return [
    'id' => 'crmapp',
    'basePath' => realpath(__DIR__ . '/../'),
    'components' => [
        'request' => [
            'COOKIEValidationKey' => 'your secret key here'
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false
        ],
        'db' => require(__DIR__ . '/db.php')
    ],
    'modules' => [
        'gii' => [
            'class' => 'yii\gii\Module',
            'allowedIPs' => ['192.168.33.1']
        ]
    ],
    'extensions' => [
        require (__DIR__ . '/../vendor/yiisoft/extensions.php')
    ]
];

extensions file:

扩展文件:

$vendorDir = dirname(__DIR__);

return array (
  'yiisoft/yii2-bootstrap' => 
  array (
    'name' => 'yiisoft/yii2-bootstrap',
    'version' => '2.0.5.0',
    'alias' => 
    array (
      '@yii/bootstrap' => $vendorDir . '/yiisoft/yii2-bootstrap',
    ),
  ),
  'yiisoft/yii2-gii' => 
  array (
    'name' => 'yiisoft/yii2-gii',
    'version' => '2.0.4.0',
    'alias' => 
    array (
      '@yii/gii' => $vendorDir . '/yiisoft/yii2-gii',
    ),
  ),
);

I digged it a little bit. It seems problem is about the alias of the assets folder.

我把它挖了一点。似乎问题在于资产文件夹的别名。

In GiiAsset.php file, there is this codeblock:

在GiiAsset。php文件,有这个代码块:

...
class GiiAsset extends AssetBundle
{
    public $sourcePath = '@yii/gii/assets';
...

which returns

它返回

/var/projectsRoot/crmapp/src/vendor/yiisoft/yii2/gii/assets

but it normally should return

但它通常会回来。

/var/projectsRoot/crmapp/src/vendor/yiisoft/gii/assets

so it is adding an unnecessary yii2 to the path.

所以它在路径上添加了不必要的yii2。

I tried to change the $sourcePath in extensions.php file, but changing the value here does not effect the result in any way.

我试着在扩展中改变$sourcePath。php文件,但是改变这里的值不会对结果产生任何影响。

Any ideas?

什么好主意吗?

--UPDATE--

While I was fiddling with things, I tried to define the alias to force the correct value; as follows:

当我在摆弄东西的时候,我试着定义一个别名来强制正确的值;如下:

Yii::setAlias('@yii/gii', $vendorDir . '/yiisoft/yii2-gii');

when I try to run the application with this setting I get following error:

当我尝试使用这个设置运行应用程序时,会出现以下错误:

The file or directory to be published does not exist: /var/projectsRoot/crmapp/src/vendor/bower/bootstrap/dist

要发布的文件或目录不存在:/var/ projectsroot /crmapp/src/vendor/bower/bootstrap/dist。

When I change the alias definition to this:

当我将别名定义改为:

Yii::setAlias('@yii/gii', $vendorDir . '/yiisoft/yii2-gi');

I get following error:

我得到以下错误:

The file or directory to be published does not exist: /var/projectsRoot/crmapp/src/vendor/yiisoft/yii2-gi

要发布的文件或目录不存在:/var/ projectsroot /crmapp/src/vendor/yiisoft/yii2-gi。

I'm quite confused with this behavior. What would be causing this?

我对这种行为很困惑。这会导致什么呢?

2 个解决方案

#1


0  

I ended up with deleting my vendor folder and composer.json file, and creating it back with following content:

我最后删除了我的供应商文件夹和作曲家。json文件,并以以下内容创建它:

{
    "require": {
        "codeception/codeception": "*",
        "fzaninotto/faker": "*",
        "yiisoft/yii2": "*",
        "yiisoft/yii2-gii": "*"
    }
}

When I launched the gii, it again threw the following exception:

当我启动gii时,它又一次抛出了以下的异常:

The file or directory to be published does not exist: /var/projectsRoot/crmapp/src/vendor/bower/jquery/dist

要发布的文件或目录不存在:/var/ projectsroot /crmapp/src/vendor/bower/jquery/dist。

I renamed the vendor/bower-asset folder to vendor/bower and it works now.

我将供应商/bower-asset文件夹重新命名为供应商/bower,现在它可以工作了。

I probably messed up with something before without noticing, but I'm not certain why it is looking for bower, instead of bower-asset. Renaming the bower-asset to bower seems to solve it.

我可能在没有注意到之前就把事情搞砸了,但我不确定它为什么要找bower,而不是bower-asset。将bower-asset重新命名为bower似乎可以解决这个问题。

UPDATE

Thanks to jacmoe from the original Yii forum, it has finally solved.

多亏了最初的Yii论坛的jacmoe,它终于解决了。

It seems these two lines need do be present in composer.json in order to automatically create bower folder, instead of bower-asset.

这两条线似乎需要在作曲家中出现。json是为了自动创建bower文件夹,而不是bower-asset。

"extra": {
    "asset-installer-paths": {
        "npm-asset-library": "vendor/npm",
        "bower-asset-library": "vendor/bower"
    }
}

Original conversation can be found at here:

原始的对话可以在这里找到:

These lines are automatically created when you install the basic application template, but when installing the bare code base, you need to manually write them.

这些行是在安装基本应用程序模板时自动创建的,但是在安装裸代码库时,您需要手工编写它们。

#2


0  

I have similar problem with my app based on yii2-app-advanced, but separated from @common. Solution is just add vendorPath attribute to application config.

我的app基于yii2-app-advanced,但与@common分离,我也有类似的问题。解决方案只是将vendorPath属性添加到应用程序配置中。


推荐阅读
  • yii框架目录结构详细分析说明
    php教程|php手册yii,目录结构php教程-php手册yii框架目录结构详细分析说明猫狗大战源码,华为云电脑ubuntu,梦见放走很多爬虫,parttmpphp,seo页面描 ... [详细]
  • 搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的详细步骤
    本文详细介绍了搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的步骤,包括环境说明、相关软件下载的地址以及所需的插件下载地址。 ... [详细]
  • PHP图片截取方法及应用实例
    本文介绍了使用PHP动态切割JPEG图片的方法,并提供了应用实例,包括截取视频图、提取文章内容中的图片地址、裁切图片等问题。详细介绍了相关的PHP函数和参数的使用,以及图片切割的具体步骤。同时,还提供了一些注意事项和优化建议。通过本文的学习,读者可以掌握PHP图片截取的技巧,实现自己的需求。 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • 实现一个通讯录系统,可添加、删除、修改、查找、显示、清空、排序通讯录信息
    本文介绍了如何实现一个通讯录系统,该系统可以实现添加、删除、修改、查找、显示、清空、排序通讯录信息的功能。通过定义结构体LINK和PEOPLE来存储通讯录信息,使用相关函数来实现各项功能。详细介绍了每个功能的实现方法。 ... [详细]
  • Iamtryingtocreateanarrayofstructinstanceslikethis:我试图创建一个这样的struct实例数组:letinstallers: ... [详细]
  • 本文介绍了如何在Azure应用服务实例上获取.NetCore 3.0+的支持。作者分享了自己在将代码升级为使用.NET Core 3.0时遇到的问题,并提供了解决方法。文章还介绍了在部署过程中使用Kudu构建的方法,并指出了可能出现的错误。此外,还介绍了开发者应用服务计划和免费产品应用服务计划在不同地区的运行情况。最后,文章指出了当前的.NET SDK不支持目标为.NET Core 3.0的问题,并提供了解决方案。 ... [详细]
  • 本文介绍了在go语言中利用(*interface{})(nil)传递参数类型的原理及应用。通过分析Martini框架中的injector类型的声明,解释了values映射表的作用以及parent Injector的含义。同时,讨论了该技术在实际开发中的应用场景。 ... [详细]
  • clickhouse 二(springboot+mybatis配置clickhouse,实现插入查询)
    原标题:clickhouse二(springboot+mybatis配置clickhouse,实现插入查询)开发步骤 ... [详细]
  • 原标题:(C语言实现)页面置换——先进先出算法(FIFO)一、设计目的:加深对请求页式存储管理实现原理的理解,掌握页面置换算法中的 ... [详细]
  • GetWindowLong函数
    今天在看一个代码里头写了GetWindowLong(hwnd,0),我当时就有点费解,靠,上网搜索函数原型说明,死活找不到第 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
  • Ihaveaworkfolderdirectory.我有一个工作文件夹目录。holderDir.glob(*)>holder[ProjectOne, ... [详细]
  • python3 nmap函数简介及使用方法
    本文介绍了python3 nmap函数的简介及使用方法,python-nmap是一个使用nmap进行端口扫描的python库,它可以生成nmap扫描报告,并帮助系统管理员进行自动化扫描任务和生成报告。同时,它也支持nmap脚本输出。文章详细介绍了python-nmap的几个py文件的功能和用途,包括__init__.py、nmap.py和test.py。__init__.py主要导入基本信息,nmap.py用于调用nmap的功能进行扫描,test.py用于测试是否可以利用nmap的扫描功能。 ... [详细]
author-avatar
ACE纞_814
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有