how to add extensions to vendor manually in yii2 [duplicate] - yii2

This question already has answers here:
How do I install Composer PHP packages without Composer?
(7 answers)
Closed 4 years ago.
i want to add https://github.com/postaddictme/instagram-php-scraper in yii2 .
i copyed vendor from instagram-php-scraper project to yii2's vendor
this is my error :
Class 'InstagramScraper\Instagram' not found
project extensions(instagram-php-scraper) is not developed for yii2 .
What other changes should I do?

I suppose you have have used composer to install Yii2;
Use composer to add the required package:
composer require raiym/instagram-php-scraper
See also :
https://github.com/postaddictme/instagram-php-scraper#installation
This way, the classes will be added to composer autoload functionality

Edit composer.json file and add your extensions in require save and run composer update in cmd
"require": {
.
.
.
"raiym/instagram-php-scraper": "^0.8.24"
},

Related

Package installation error in Yii2 framework?

I have a requirement to use PHPOffice/PhpSpreadsheet, to install PhpSpreadsheet I followed this link.
So I installed PhpSpreadsheet into my project using 'composer' by running the command
composer require phpoffice/phpspreadsheet
at command prompt while installing it said that
Using version dev-master for phpoffice/phpspreadsheet
and was installed successfully(FYI check Screenshot), after installing when I tried to login into my application, I am getting a different error as
Cannot redeclare PHPMailerAutoload()
(previously declared in" for emails I am using 'phpmailer' including the path as
require_once('../vendor/phpmailer/PHPMailerAutoload.php');
as my "PHPMailer" folder resides in 'vendor' folder of Yii2 framework.
By the way I am building my application on Yii2 framework and I am very new to Yii2 framework.
Can anyone please tell, how to fix this? Thanks.
You don't have to use require for packages installed via composer. Yii autoload's feature will take care for that. You just have to write the appropriate use statements in your code. Actually, the mailer is a component declared into the main app, so you don't need the use statement at all
Yii::$app->mailer->compose('/my/mail_view', ['model' => $model])
->setFrom([Yii::$app->params['myMail'] => 'My Name'])
->setTo($model->email)
->setSubject('My subject')
->send();

How to remove extension from vendor?

I have cloned a project written in Yii2. There are some extensions in vendor folder which I want to remove them from project. How can I do this? I am sure they are installed using composer because they are noted in composer.lock file.
If you just want to remove packages from the vendor folder you can use composer command:
composer remove package/name
If you want to remove calls to these packages in the project you need to do this manually.
You can delete the line with the name of the package from the composer.json and make in command line composer update

Yii2 : How to update only Font Awesome library using composer?

I have update only latest Font Awesome library using composer without update other packages in yii2.
Thanks in advance.
1st. Require version of library which you need to update:
php composer.phar require cinghie/yii2-fontawesome "2.1"
2nd. Update it via composer:
composer.phar update cinghie/yii2-fontawesome
Or you can just do 2nd if don't need specific version to update single library.
Odd question.
Because there is no FontAwesome installed with Yii 2 .. :)
However, if you want to install it, or update it, then you should use this package name:
bower-asset/fontawesome
You could also install a Yii 2 extension that gives you an asset bundle with fontawesome:
https://packagist.org/packages/rmrevin/yii2-fontawesome
I am curious:
What package are you using that requires fontawesome?
And why do you want to update the fontawesome package?

what a part does bower/bower-asset play in php application such as yii2

Recently I deployed some projects like trntv/yii2-starter-kit and so on.but all applications are publishing assets on '#vendor/bower' instead of'#vendor/bower/bower-asset'. I have read the question Yii2 Composer manage package in bower and bower-vendor and solved it . but I still feel confused about the directory vendor/bower/bower-asset.
What's the part does bower/bower-asset play in php application? it is not a composer package but many theme store in there. Furthermore, bower is a dependency management for javascript just like Composer for PHP , but how does it solve dependency for js package by PHP on this occasion that I have not install node.js environment?
The idea of Composer Asset Plugin is to download Bower / NPM packages and manage their dependencies without having Node JS, Bower and NPM installed (through PHP / Composer). Also it adds possibility to add JavaScript dependencies for PHP packages that use JavaScript libraries.
See for example yii2-bootstrap Yii2 extension (PHP) has a dependency on Bootstrap (JS + CSS):
"bower-asset/bootstrap": "3.3.* | 3.2.* | 3.1.*"
When you run composer install or composer update, all JS dependencies will be installed to vendor/bower folder.
This is built into the core, but very ambiguous, receives a lot of criticism and there are plans to remove it in 2.1.0 (as far as I remember, it was included before release of 2.0 even it was unstable). Unfortunately this is required and there is no normal way to disable it.
You can read more info on the extension's Github page.
As for folder name, it should be named bower, not bower-asset, if you installed everything correctly.
It's named like so automatically, make sure you have the latest version of plugin:
composer global require "fxp/composer-asset-plugin:~1.1.1"
I'd recommend to even switch to:
composer global require "fxp/composer-asset-plugin:*"
If you have problems or errors, execute:
composer global remove "fxp/composer-asset-plugin"
Then reinstall it again, delete vendor and composer.lock in your application folder and run:
composer install

Yii2 DatePicker installation

Found documentation about this widget here and library here.
Tried to install with Composer and failed:
Tried to copy "yiisoft/yii2-jui": "~2.0.0" to composer.json and then update Composer and failed again:
Class 'yii\jui\DatePicker' not found
Is there any way to install this extension without using Composer?
Did you install composer global require "fxp/composer-asset-plugin:1.0.0" ? It is a NPM/Bower Dependency Manager for Composer that required by yii2. Before installing yii2-jui try this command, and then composer update