How to hide a raw in view.php file using Yii2 Framework - yii

I have this raw in my view.php file:
[
'attribute' => 'Descrizione',
'format' => 'html',
'value' => function ( $model ) {
return nl2br($model->Descrizione);
},
'label' => 'Descrizione',
],
What I want is to hide the entire field if the value don't contains any character, so if is = "" OR is NULL. So I want to hide the entire field "Descrizione".
Which is the option that I have to add in this code?
Thank you very much

You can use the options attribute to set a CSS style.
for example:
empty($model->Descrizione)?'hidden':''
https://www.yiiframework.com/doc/api/2.0/yii-widgets-activefield
Eg:
<?= $form->field($model, 'Descrizione',['options'=>['class'=>empty($model->Descrizione)?'hidden':'']])->textInput(['maxlength' => true, 'disabled' => true]) ?>
Make sure the class "hidden" is actually defined - if you are using bootstrap you can use d-none

Are you using Gridview or DetailView ?
If DetailView, try :
[
'attribute' => 'Descrizione',
'label' => 'Descrizione',
'visible' => !empty($model->Descrizione),
'format' => 'ntext',
],

Related

Yii2 - Multiple Dropzone Widget doesn't work

I'm working with Yii2 to develop an intranet portal.
I have to put multiple widget in same page but it doesn't work.
Give me this error
Dropzone already attached.
And my code is
...
<?= \kato\DropZone::widget([
'id' => 'dzImages',
'dropzoneContainer' => 'dzImages',
'options' => [
'url' => 'index.php?r=orders/upload&uid='.$model->ref,
'maxFilesize' => '10',
'acceptedFiles' => "image/*",
],
]); ?>
</p>
<p>
<?php echo \kato\DropZone::widget([
'id' => 'dzPDF',
'dropzoneContainer' => 'dzPDF',
'options' => [
'url' => 'index.php?r=orders/uploadpdf&uid='.$model->ref,
'maxFilesize' => '10',
'acceptedFiles' => ".pdf",
],
]);
?>
</p>
...
How can i resolve it?
Looking at the code of the widget, the 'id' parameter seems to be used differently than one would expect, instead you should probably set previewsContainer property too.
The ID parameter seems to be used as a JavaScript variable here:
https://github.com/perminder-klair/yii2-dropzone/blob/41e8145d940cc9955011138a9f16ad80e9831423/DropZone.php#L75

How to Configure yiibooster

thanks for reading, i am wondering how to install
YiiBooster
, do i need to install
YiiBootstrap
first ?
I want to install it by hand , is it enough to extract it to extensions folder and than configure the main.php or is there something i am missing ?
Also how can i make this point to the right path
'booster' => array(
'class' => 'path.alias.to.booster.components.Booster',
),
You don't need to install bootstrap. Yiibooster includes all bootstrap files it needs. Just download Yiibooster, unpack to the extension folder and add the below to your main config file,
'booster' => array(
'class' => 'ext.yiibooster.components.Bootstrap',
'responsiveCss' => true,
),
Then add the following in the preload section of the config,
'booster',
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
// preloading 'log' component
'preload'=>array('log','bootstrap'),
// application components
'components'=>array(
//
'bootstrap' => array(
'class' => 'bootstrap.components.Booster',
'responsiveCss' => true,
),
Rename folder name yiibooster-4.0.1 to yiibooster
Step 1:
'preload' => array(
'booster',
),
Step 2:
'booster' => array(
'class' => 'ext.yiibooster.components.Booster',
'responsiveCss' => true,
),
Note: Booster this Class name
//Use view file
<?php
$this->widget('booster.widgets.TbExtendedGridView',
array(
'filter' => $model,
'fixedHeader' => true,
'type' => 'striped bordered',
'headerOffset' => 40,
// 40px is the height of the main navigation at bootstrap
'dataProvider' =>$model->search(),
'template' => "{items}",
'columns' => array(
'id',
'firstname',
'lastname',
'age',
'address',
'email',
),
)
);
?>

yiibooster show already added record in select2 widget

I have already added data using select2 yiibooster widget but how i can update data using select2 widget.
how i show already added records in yiibooster select2 widget
<?php
echo $form->labelEx($model, 'measurement');
$this->widget(
'bootstrap.widgets.TbSelect2', array(
'name' => 'measures[]',
'data' => Ingredient::getmeasurementhere(),
'htmlOptions' => array(
'multiple' => 'multiple',
'class' => 'span3',
'id' => 'select1li_id'
),
//'events' => array('change' => 'js:getsubcategories')
)
);
?>
i am getting data using Ingredient::getmeasurementhere() function how i fetch this using update or write new function but how to show in select2 ?
Thanks in advance

CClientScript duplicates the output

I'm trying to use this extension in a partial view, in my registration module...
$form->widget('ext.tokenInput.TokenInput', array(
'model' => $model,
'attribute' => 'tags',
'url' => array('wizard/search'),
'options' => array(
'allowCreation' => false,
'preventDuplicates' => true,
'allowFreeTagging' => false,
'minChars' => 2,
'theme' => 'facebook',
)
));
...and assets (javascript and CSS files) are duplicated.
Basically I can see in the HTML code multiple occurrences of these files.
I have the same problem if I try to add custom JS files in the same partial view.
I specify POS_HEAD and I can see the code in <head> and in the middle of the page.
Why CClientScript duplicates assets if I add them in a partial view?
Thanks a lot!

Yii CListView summary text

Is there any way to hide "Summary" for CListView without loosing pagination. By summary i mean text like "Displaying 1-2 of 2 result(s).". Or maybe I should use different widget?
Try the following to get more control over the look of your CListView output:
'template'=>'{items} {pager}'
You can even use HTML in the template.
Ok, I didn't get it at first, when looking into CListView code, but setting 'summaryText' to '' will do the work. I've realised that second time when I was staring at $summaryText === null
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'summaryText'=>'',
'itemView'=>'_indexview',
));
Here is the example for CListView:
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataProvider,
'itemView' => '_view',
'ajaxUpdate' => false,
'emptyText' => 'No records found.',
'summaryText' => "{start} - {end} из {count}",
'template' => '{summary} {sorter} {items} {pager}',
'sorterHeader' => 'Sort by:',
'sortableAttributes' => array('title', 'price'),
'pager' => array(
'class' => 'CLinkPager',
'header' => false,
'cssFile' => '/css/pager.css',
'htmlOptions' => array('class' => 'pager'),
'maxButtonCount' => '10',
'prevPageLabel'=>'←',
'nextPageLabel'=>'→',
'header'=>'Pages: ',
),
));
You should try this:
'summaryText' => FALSE,
You may hide it by adding CSS in the page like below.
<style>
.summary{
display:none;
}
</style>
Here is my suggestion
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $best_seller_data,
'itemView' => 'alsoBestseller',
'summaryText'=>false,
));