Just tried to load one of the components and having some difficulty. It may be something not set up correctly on my maching.
I’m trying to user the yii2-sweet-alert component.
I added
"yii2mod/yii2-sweet-alert": "*"
To composer.json file. I have done this for other components and seemed to work just fine, but when I run the ‘composer update’ on the project I get the dreaded -
Problem 1
- The requested package yii2mod/yii2-sweet-alert could not be found in any version,
there may be a typo in the package name.
Do I need to do anything to allow pulling the yii2mod components like others?
Ok, learning more about the loader and assets their are bugs Sweet Alert components code -
The location/name of the sourcePath is incorrect, as many of the names have ‘sweet-alert’ instead of ‘sweetalert’ which is what is being used. (look in .../vendors/sweetalert)
Also it had names referencing ‘sweet-alert’ where were changed to ‘sweetalert’
Here is the AlertAsset.php that I modifed and now works -
<?php
namespace yii2mod\alert;
use yii\web\AssetBundle;
/**
* Class AlertAsset
* @package yii2mod\alert
*/
class AlertAsset extends AssetBundle
{
/**
* @var string the directory that contains the source asset files for this asset bundle.
* A source asset file is a file that is part of your source code repository of your Web application.
*/
public $sourcePath = '@bower/sweetalert/dist'; /*was lib*/
/**
* @var array list of JavaScript files that this bundle contains. Each JavaScript file can be
* specified in one of the following formats:
*/
public $js = [
'sweetalert.min.js', /* was sweet-alert.min.js */
];
/**
* @var array list of CSS files that this bundle contains. Each CSS file can be specified
* in one of the three formats as explained in [[js]].
*/
public $css = [
'sweetalert.css' /* ws sweet-alert.css */
];
}
The code now in my view looks like this -
<?php echo yii2mod\alert\Alert::widget([
'useSessionFlash' => false,
'options' => [
'title' => 'Success message',
'type' => 'success', // IMPORTANT THIS IS ALL LOWER CASE, EXAMPLES SHOWN ON GITHUB IS INCORRECT
'text' => "You will not be able to recover this imaginary file!",
'confirmButtonText' => "Yes, delete it!",
'cancelButtonText' => "No, cancel!"
]
]);
?>