Invalid Parameter error for Gii assets folder

Hey guys,

I am trying to learn Yii 2 from a book. Somewhere along the line it instructs me to install gii and create crud files with it.

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

My bootstrap, config and extensions files are attached.

6896

web.php

6897

index.php

6898

extensions.php

What am I missing?

try


composer require yiisoft/yii2 dev-master

:)

Framework yii2 include default Gii


/web/index.php?r=gii/index

Normally I would use that but the book (Web Application Development with Yii 2 and PHP) is instructing me to build the application from scratch. So I have to build it seperately.

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

In GiiAsset.php file, there is this codeblock:




...

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.

I found a place where @yii/gii has defined. It is the extensions.php file:




  array (

    'name' => 'yiisoft/yii2-gii',

    'version' => '2.0.4.0',

    'alias' => 

    array (

      '@yii/gii' => $vendorDir . '/yiisoft/yii2-gii',

    ),

  ),

but changing the value here does not effect the result in any way.

Is this behavior normal?

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:

When I change the alias definition to this:


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

I get following error:

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

You have a typo.

Look closer at your last alias setting - ‘gii’ not ‘gi’. ;)

That is actually intentional. Just wanted to test what happens when I change the alias definition :)

When I type gii, I get this one:

when I don’t define the alias at all, I get this one:

Where it should be like that:


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

It is probably defined at somewhere else, but I just can’t find it.

I am not sure what you are trying to do here…

I do know, however, that this is how the relevant part of my composer.json looks like:


	"require-dev": {

    	"yiisoft/yii2-gii": "*",



And the config for my frontend (main-local.php):


  $config['bootstrap'][] = 'gii';

  $config['modules']['gii'] = [

	'class' => 'yii\gii\Module',

...

The thing is, you don’t need to specify any alias or anything.

Just tell Yii that you want to use the module, and that’s it.

Review the contents of your composer.json.

well, I’m just trying to follow the instructions in the mentioned book. It just installs the bare code base and integrate the modules one by one while teaching them. But as long as I install the components via composer, they should behave the same, right?

This is the content of my composer.json file:


{

    "require": {

        "codeception/codeception": "*",

        "fzaninotto/faker": "*",

        "yiisoft/yii2": "*",

        "yiisoft/yii2-gii": "*"

    }

}



I did not required the dev packages. Does it make any difference?

config file looks pretty much the same. Here is the releavant section of mine:


'modules' => [

        'gii' => [

            'class' => 'yii\gii\Module',

            'allowedIPs' => ['192.168.33.1']

        ]

    ],



thats actually what I thought, but when I got the error in the first place, I started to fiddle with aliases and all.

And with above mentioned config and composer.json files, I still have this 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

I wonder if I messed something up while installing gii? What is the proper way to uninstall and reinstall it?

Oh, by the way, I probably should have mentioned that I am strictly following the conventions and instructions in the book and I did not installed the basic application template. I installed the bare code base with following command:


php composer.phar require "yiisoft/yii2:*"

Are you bootstrapping the Gii module?

Edit:

Take a look at vendor/yiisoft/yii2-gii/Module.php

What exactly do you mean by bootstrapping it?

If you mean adding it to configuration file, yes that has been done.

config/web.php




    'modules' => [

        'gii' => [

            'class' => 'yii\gii\Module',

            'allowedIPs' => ['192.168.33.1']

        ]

    ],



I have also added this just before the above config section:


'bootstrap' => ['gii'],

but nothing changed :(

Do you have any idea why it is looking for files in vendor/yiisoft/yii2/gii/assets, instead of vendor/yiisoft/yii2-gii/assets?

I think it would be a good time to remove the entry for gii in your composer.json and delete the ‘vendor’ folder and run composer install again.

Then perform a require-dev for the gii module instead.

Gii in production is a very bad idea.

Before you do that, you should clean the composer cache and maybe - and I recommend that you do that - create a standard Yii application using the ‘basic’ Yii2 composer template.

If that works/fails, then you’d be wiser.

You also need to clean up whatever configuration changes you made in your quest to make Gii work.

Hi, thanks for the response.

I just removed the global .composer folder, local composer.json and composer.lock files and deleted the vendor folder. (just in case :) )

Then installed the composer asset plugin (globally) and bare code base along with gii. My current composer.json looks like this:


 {

    "require": {

        "codeception/codeception": "*",

        "fzaninotto/faker": "*",

        "yiisoft/yii2": "*"

    },

    "require-dev": {

        "yiisoft/yii2-gii": "*"

    }

}



(I installed the bare code base, not basic app template - in order to reproduce the error)

I still get this error:

When I rename the vendor/bower-asset folder to vendor/bower, all works great.

Later on I also installed the basic application template, it works without a glitch, but bower folder there named as bower instead of bower-asset, by default.

In this point I have a couple of questions:

  • Is this behavior for bare code base expected?

  • Would I break anything if I manually rename the bower-asset folder to bower? (So far all looks good)

I know that best thing to do is installing the basic app template, but in order to follow the book, I need the bare code base, as it is teaching things by building things and adding them up one by one.

You probably need to have this section in your composer.json:


	"extra": {

    	"asset-installer-paths": {

        	"npm-asset-library": "vendor/npm",

        	"bower-asset-library": "vendor/bower"

    	}

	}



Bingo! Thank you very much!

If I understand right, this section instructs the composer to install the related asset folders to specified paths (e.g. npm-asset to npm and bower-asset to bower). Is that correct?

Is there any manual or resource that I can read more about this?

Thanks again.

I don’t think so, except from the docs for the Composer asset plugin:

https://packagist.org/packages/fxp/composer-asset-plugin

I could be wrong, though. :)

Ok, gonna look into that. Thanks again :)

Take a look at:

That is what I was looking for :) Thanks, you are really kind.

You are welcome :)

That is part of my procrastinate displacement activities - happens a lot when I have a programming job that needs to be done. :P