Image not displayed

Hello everyone,

I am using the yii\jui\DatePicker widget to show the calendar, but when i tried to show it’s image that i added to my assets folder under images folder, nothing displayed for my image.

This is the code:


<?= $form->field($model2, 'task_start')->widget(DatePicker::className(),[

'options' => [

         'buttonImage'=>Yii::$app->request->baseUrl.'/images/calendar.png',

         'buttonImageOnly' => true,

         'showOn' => 'button',

         'language' => 'en', 

         'dateFormat' => 'yy-mm-dd']

]) ?>

I would like to hear your views about this issue, thank you and have a nice day.

I am not sure as I never used that, but I think, Yii::$app->assetManager->baseUrl should work for you if you have assetManager component.

the thing is that this code is working and it shows the image:


 <img src="<?= Yii::$app->request->baseUrl ?>/images/calendar.png">

but when i tried to use it in the DatePicker widget it is not working, and for the assetManager i don’t know how to create it, any clue how to solve it, thanks.

Simplicity, can you show to us a html output block from your site ?

I attached it, as you can see there is no image beside the Task Start and End boxes, just beside the reset button where i used this code:


<img src="<?= Yii::$app->request->baseUrl ?>/images/calendar.png">

Any help? thanks.

I am sorry, I could not understand the question and I answered something wrong. You may get some ideas from this post below. Some issues and solutions are covered.

http://www.yiiframework.com/forum/index.php/topic/59125-yiijuidatepicker-buggy/page__p__265972__fromsearch__1#entry265972

But this is related to the dateFormat, not for the image.

May be ‘buttonImage’=>’/images/calendar.png’ works.

Anyway, there is a new Yii2-jui-master version preparing for release.

I did not use image for this I use glyphicon.




  <?= $form->field($model,'datefrom',[


           'inputTemplate' => '<div class="input-group">{input}<span class="input-group-btn "><button class="btn btn-default" type="button"><i class="glyphicon glyphicon-calendar"></i></button></span></div>',

            ])->widget(DatePicker::className(),

         ['language' => 'en', 'dateFormat' => 'yyyy-MM-dd','options'=>['class'=>'form-control']]


         )




Not working also, thanks.

Hello ezekel, it’s working as “template” not “inputTemplate”, but the button is unclickable.

Hey just try giving the image path from the images directory.

I mean your code should be something like :

<?= $form->field($model2, ‘task_start’)->widget(DatePicker::className(),[

‘options’ => [

     'buttonImage'=&gt;'/images/calendar.png',         // it automatically picks images from the images folder


     'buttonImageOnly' =&gt; true,


     'showOn' =&gt; 'button',


     'language' =&gt; 'en', 


     'dateFormat' =&gt; 'yy-mm-dd']

]) ?>

Hit like if my solutions are helping you out.

Simplicity, we set ‘basePath’ in the application configuration file, main.php.

Relative to that file, adding ‘\…’ and path, you can give the right path to your image file.

eg: Yii::$app->basePath.’\…\path\to\your\image.png’;

Hello hrnair, it’s my first time setting a ‘basePath’, could you show me an example? thanks

It didn’t work

Sorry that nothing worked. Path is required only if the image is manipulated. I suggested because all the other things failed for you. You can check the HTML source in the browser(Control+U) and see what html code is generated when you use the relative url (’/images/calendar.png’) and the absolute url (Yii::$app->baseUrl.’/images/calendar.png’).

Hope you can find out the solution.