N
N
nikitinandrey19902018-06-03 22:02:24
Yii
nikitinandrey1990, 2018-06-03 22:02:24

How to add pictures in yii2 module?

Good evening. I can’t understand how pictures are connected in the module.
Created the user module, created there

created there
5b1439b06dadb889629989.png

I connected the template, all the scripts, styles, everything works fine, but there are problems with the pictures, I just can’t connect .....
asset/AppAsset.php
<?php

namespace app\modules\user\assets;

use yii\web\AssetBundle;

class AppAsset extends AssetBundle
{
    public $sourcePath = '@app/modules/user/web';
    public $css = [
        'css/font-awesome.css',
        'css/custom.css',
        'http://fonts.googleapis.com/css?family=Open+Sans',
    ];
    public $js = [
        'js/jquery.metisMenu.js',
        'js/morris/raphael-2.1.0.min.js',
        'js/morris/morris.js',
        'js/custom.js',
    ];
    public $depends = [
        'yii\web\YiiAsset',
        'yii\bootstrap\BootstrapPluginAsset',
    ];
}
in template
<?= Html::img("@web/img/find_user.png", ['class' => 'user-image img-responsive'])?>


Perhaps everything is simpler than I wind myself up, but I can’t think of it ...... Please help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Smirnov, 2018-06-03
@nikitinandrey1990

In view:

<?php
$bundle = $this->getAssetManager()->getBundle('app\modules\user\assets\AppAsset'); // получить бандл
?>

Image output:
<?= Html::img($bundle->baseUrl . "/img/find_user.png", ['class' => 'user-image img-responsive'])?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question