Yii2 Composer and Bower issue - php

I am facing a problem during Yii2 installation.
I have repository on Bitbucket. Its obvious that after git clone/fetch/pull i need to install dependencies. Everything that i am trying to do is always inside newly created php 7.2.0 Docker image machine (Bitbucket Pipelines). So here is the list of commands that i have:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
php composer.phar create-project
My composer.json file is equals to one from official repository.
The problem is that web/assets directory is lacking of files. It has autogenerated directories and only yii, yii activeForm, captcha, gridView and validation JS files.
As i know composer-asset-plugin not used any more. At least no mention in installation guide. But even if i add php composer.phar global require "fxp/composer-asset-plugin:^1.4.2" it won't fix the issue. It looks like bower assets can't be compiled or something like that. Maybe i am wrong. I have no idea why its not working. No results during search too.
Any ideas? Thanks!

Issue come when we are using composer 2. Otherwise we can use fxp/composer-asset-plugin. MihaOo answered for basic app. For people who are using advanced app can use following configuration.
Update common/config/main.php with following config.
'aliases' => [
'#bower' => '#vendor/bower-asset',
'#npm' => '#vendor/npm-asset',
],
Original config file from yii2 advanced app - configuration file
More information about this - Yii2 Forum
Complete solution in Asset packagelist -Asset packagelist

For people who facing this issue. I've checked everything once more, it should work but it doesn't. All essential directories have correct rights. Everything is working perfectly except this bower issue. I doublecheck on local PC. Can't reproduce.
However after about 10 takes to fix, it starts working correctly. Maybe it is yii\web\AssetManager issue or something, i still don't know, time will show.
UPD 22.10.2018
You just need to add this code to you cofig file and it will fix this issue.
'aliases' => [
'#bower' => '#vendor/bower-asset',
'#npm' => '#vendor/npm-asset'
]
It was also added to application templates

Related

Install a package using composer. How? Where?

I'm fairly new to PHP and Composer and used Linux 20 years ago. I'm developing a website on a shared hosted server (Hostinger) and trying to install a package from Cardinity (they take VISA payments). I want to use this package from my website which I've hand written in HTML/PHP/MySQL etc.
The instruction from cardinity is to execute the following (from https://github.com/cardinity/cardinity-sdk-php):
$ php composer.phar require cardinity/cardinity-sdk-php
I've changed this to:
$ php /usr/local/bin/composer.phar require cardinity/cardinity-sdk-php
So that it runs without error.
I have two questions which are:
Am I right in thinking that composer will locate and download the package (and sub-packages it requires) for me? I don't have to do anything other than execute this line?
In which directory do I execute this?
My website is in /home/u123456789/public_html. I've executed the above statement in /home/u123456789/public_html and ended up with composer.json and composer.lock files in that directory, as well as a vendor folder. However, my website doesn't pick up the package. When I execute a simple test.php file with the following code in (as advised by Cardinity):
use Cardinity\Client;
$client = Client::create([
'consumerKey' => 'YOUR_CONSUMER_KEY',
'consumerSecret' => 'YOUR_CONSUMER_SECRET',
]);
I get the error: Fatal error: Class 'Cardinity\Client' not found in /home/u123456789/public_html/dev/test.php on line 32 which is on the Client::create line. My test.php file is in the directory /home/u123456789/public_html/dev.
Does test.php have to be in the same directory as composer.json, composer.lock and vendor?
Please try and make it a bit harder for hackers and place items not as per documentation and in properties that follow your own naming convention.
Also add a security measure if some one does try to access the "default". Someone having your keys as do some real harm with a refund.

Laravel Glide installation - where do I put the config information?

I am interested in installing Glide in Laravel for an image server I need to build.
There are 3 main steps in the installation:
Run a Composer command
composer require league/glide-laravel
This step is called 'Configuration', it shows the following PHP code
Configuration:
use League\Glide\ServerFactory;
use League\Glide\Responses\LaravelResponseFactory;
$server = ServerFactory::create([
'response' => new LaravelResponseFactory(app('request'))
]);
... and step 3, which is a working example.
My question is, where does the step 2.
configuration code go?
I can't see anywhere obvious in the 'config' folder. Disclaimer: I'm a newbie to Laravel with only two sites built so far.
thank you.
The configuration code belongs in the default image controller. It is confusing in the documentation but I placed the code in the controller and it works.

Laravel 5.4 migrate:generate fails with Way\Generators\Filesystem\FileNotFound error

I am trying to use Xethron/migrations-generator in a Laravel 5.4 project in order to generate migration files for all of the tables in my database. I followed the instructions in the README file for Laravel 5 to the letter. After resolving a complaint or two (had to install php7.0-xml extension), I try to run it but it spits out an error like so:
$ php artisan migrate:generate
Using connection: mysql
Generating migrations for: group_product_assoc, groups, product_hierarchy_assoc, product_product_assoc, products, replist, sessionsOLD, stores, tree, users, zipcode_coordinates
Do you want to log these migrations in the migrations table? [Y/n] :
> n
Setting up Tables and Index Migrations
[Way\Generators\Filesystem\FileNotFound]
/var/www/my-project/vendor/way/generators/src/Way/Generators/templates/migration.txt
I have reported this issue to Xethron on github and apparently I'm not the only person having this problem.
Can anyone tell me how to get this working? I'm not especially fluent with Laravel or Composer so please don't skimp on the basic explanations. I'm using:
Ubuntu 16.04
PHP 7.0.15
Laravel 5.4
I had the same issue. You need to copy the following file to the location:
https://github.com/Xethron/Laravel-4-Generators/tree/master/src/Way/Generators/templates/migration.txt
In to this folder ( it's possible, this does not exist - so you can either create the folders OR change the configuration file (config.php) in vendor Xethron
/var/www/my-project/vendor/way/generators/src/Way/Generators/templates/
J. Doe's answer is essentially correct as far as I can tell. I am posting a more complete solution here to describe the exact steps I took to fix the issue.
Apparently, there's something wrong with the Xethron code in that it tries to refer to a PHP template file that is somehow not properly included/required by the Xethron package. My short-term solution seems to have worked. That solution is to first cd into the working directory:
cd /var/www/my-project
then create the directory where the file should be:
mkdir -p vendor/way/generators/src/Way/Generators/templates
then we put the template file in there in one of two ways. One way, as suggested by J. Doe is to download the file from github (https://raw.githubusercontent.com/Xethron/Laravel-4-Generators/master/src/Way/Generators/templates/migration.txt) and save it as migration.txt in the directory we just created above. Or you can cd into the working directory and execute this command:
curl https://raw.githubusercontent.com/Xethron/Laravel-4-Generators/master/src/Way/Generators/templates/migration.txt > vendor/way/generators/src/Way/Generators/templates/migration.txt
The other way is to copy the template file which is apparently in a subdirectory of the xethron package:
cp vendor/xethron/laravel-4-generators/src/Way/Generators/templates/migration.txt vendor/way/generators/src/Way/Generators/templates/migration.txt
Once the file exists in that location, You should be able to run the command again without a hitch:
php artisan migrate:generate
This issue has been resolved, simply run composer update to get the latest version.
Apologies for the inconvenience.

Laravel 4 Setup: Driver [file] not supported

I'm trying to set up an existing site that was built using Laravel 4 on my server. I've gotten stuck at an error: Driver [file] not supported. It's throwing the error from Illuminate/Support/Manager.php.
I've tried using boilerplate Laravel files for the Manager.php file, as well as the SessionManager.php file, but it still won't work. I've also tried to figure out if file is registered as a driver, but when I try to insert the code for it, I get lost because of undeclared functions.
When I try to change the default session driver in app/config/session to anything else, it just throws other errors at me. Yet this is the same way the site was originally set up on its own server, so I don't understand why it isn't working. Can anyone help me out?
I was stuck in same problem, solved it. After changing any configuration config cache must be cleared using php artisan config:cache. Hope it helps.
What is your php version?
Try to clean the session dir
app/storage/sessions
then try to clean autoload file
cd [YOUR LARAVEL ROOT DIR]
composer dump-autoload
and update composer package to be sure vendor folder is ok
cd [YOUR LARAVEL ROOT DIR]
composer update

Setting up preview of Yii2

The Yii2 preview was recently released and is available on github. I want to take it for a test drive, but the "documentation" so far gets outdated almost instantly since it is still under heavy development. I have tried to follow this guide on creating a simple CRUD app with Yii2, but it fails at the step:
php yiic.php app/create /var/www/yii2
With the error:
Could not open input file: yiic.php
Indicating that there is no file called yiic.php. The only folder within the framework folder is yii (framework/yii), and within that folder there is no file yiic.php, only Yii.php which when called in the command line gives the command list:
The following commands are available:
- asset
- cache
- help
- message
- migrate
Anyone managed to successfully setup a Yii2 app? Care to share how you got it done?
Seems like yiic has been removed for now, there are alternatives though, so read on.
It's all in the early stages, so the following method could break in the coming days/weeks/months. Therefore use with caution.
There are 2 ways to do this now:
Use composer. (I recommend this option.)
Directly copy the contents of yii2/apps/ directory to your apps directory, depending on the type of app you want to try.
There are currently 2 options for type of app - advanced, and basic. Both are in their respective directories within the yii2/apps/ directory, i.e yii2/apps/advanced and yii2/apps/basic.
For basic go through the basic readme.md, and for advanced go through the advanced readme.md.
The directions for using composer are given in the respective readme.md files. Including them here for completeness:
Basic app:
Install composer, if you don't have it.
Use composer to install the app alongwith dependencies(Yii):
php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-basic my_yii2_trial
Access app from http://localhost/my_yii2_trial/www
Advanced app:
Install composer, if you don't have it.
Use composer to install the app alongwith dependencies(Yii):
php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-advanced my_yii2_trial
According to readme, after step 2 app should be accessible, but composer was failing(see issue 439). With schmunk's tip, ran the install or install.bat command that gets copied by composer: ./install . Selected development environment (by entering choice 0 in the instructions that show up when running install command). Update: The command has been renamed to init, composer doesn't fail anymore, with fix from Qiang (check the issue 439 for more details).
Access app at: http://localhost/my_yii2_trial/frontend/www or http://localhost/my_yii2_trial/backstage/www
Here's how to copy the directory and get it working:
Basic app:
create your web-accessible directory for the app : my_yii2_trial
copy all files and folders from yii2/apps/basic/ directory to my_yii2_trial/ directory.
modify the my_yii2_trial/www/index.php file to point to the correct path for Yii.php.
For me it was within yii2/framework/yii/
comment the line that tries to include ../vendor/autoload.php file, I couldn't find that file anywhere, so its probably for some future use. it is the autoloader provided by composer.
Access from browser : http://localhost/my_yii2_trial/www
Advanced app:
create your web-accessible directory for the app : my_yii2_trial
copy all files and folders from yii2/apps/advanced/ directory to my_yii2_trial/ directory.
modify the my_yii2_trial/frontend/www/index.php file to point to the correct path for Yii.php. Similarly modify backstage/www/index.php.
comment the line that tries to include ../vendor/autoload.php file in both the index.php of backstage and frontend.
Access app at: http://localhost/my_yii2_trial/frontend/www or http://localhost/my_yii2_trial/backstage/www
Some important links to read more about this: issue 77, issue 108, issue 131, and wiki comment.
I am not sure how composer's autoloader is being used, so can't comment on that. Also in future versions, backstage might be renamed to backend.

Categories