CodeGeek
(Mk K Greek)
December 5, 2014, 3:08am
1
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.
hrnair
(Harikrishnan Hr)
December 5, 2014, 9:55am
2
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.
CodeGeek
(Mk K Greek)
December 8, 2014, 3:40am
3
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.
aisogroup
(E Poremchuk)
December 8, 2014, 3:45am
4
Simplicity, can you show to us a html output block from your site ?
CodeGeek
(Mk K Greek)
December 8, 2014, 4:12am
5
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.
hrnair
(Harikrishnan Hr)
December 8, 2014, 8:05am
6
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
CodeGeek
(Mk K Greek)
December 8, 2014, 8:17am
7
But this is related to the dateFormat, not for the image.
hrnair
(Harikrishnan Hr)
December 8, 2014, 3:24pm
8
May be ‘buttonImage’=>’/images/calendar.png’ works.
Anyway, there is a new Yii2-jui-master version preparing for release.
ezekel
(Dixunei)
December 8, 2014, 5:13pm
9
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']]
)
CodeGeek
(Mk K Greek)
December 9, 2014, 3:11am
10
hrnair:
May be ‘buttonImage’=>’/images/calendar.png’ works.
Anyway, there is a new Yii2-jui-master version preparing for release.
Not working also, thanks.
CodeGeek
(Mk K Greek)
December 9, 2014, 3:37am
11
ezekel:
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']]
)
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'=>'/images/calendar.png', // it automatically picks images from the images folder
'buttonImageOnly' => true,
'showOn' => 'button',
'language' => 'en',
'dateFormat' => 'yy-mm-dd']
]) ?>
Hit like if my solutions are helping you out.
hrnair
(Harikrishnan Hr)
December 9, 2014, 12:30pm
13
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’;
CodeGeek
(Mk K Greek)
December 10, 2014, 5:57am
14
hrnair:
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
hrnair
(Harikrishnan Hr)
December 10, 2014, 9:27am
16
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.