In my web application, I want to set a default value to CHtml::textArea.
In my view,
<?php echo CHtml::textArea('answer' . $no, '', array('rows' => 6, 'cols' => 50, 'class' => "form-control",'value'=>$exam->answer)); ?>
But, this is not working. How can I do this?
You can set it directly as the second parameter:
CHtml::textArea('answer' . $no, $exam->answer, array(
'rows' => 6, 'cols' => 50, 'class' => "form-control")
);
See CHtml::textArea for more details.
Related
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',
],
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
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',
),
)
);
?>
I'm using Yii-Booster TbTabs. I'd love to be able to nest CGridView in one of the tabs. I'm trying the following but getting the error "Object of class CGridView could not be converted to string".
$this->widget(
'bootstrap.widgets.TbTabs',
array(
'type' => 'tabs',
'tabs' => array(
array(
'label' => 'Tab 1',
'content' => '',
),
array(
'label' => 'Tab with grid view',
'content' =>$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'entry-subject-grid',
'dataProvider'=>$relatives->search(),
'filter'=>$relatives,
'columns'=>array(
'id',
'subject',
array('class'=>'CButtonColumn',),),)),),
array(
'label' => 'Tab 3',
'content' =>'description content',
),
),
)
);
This there any way that I can pass this object into a tab view (of example Im able to pass ckEditor quiate happily into a tab with the following
array(
'label' => 'Entry',
'content' => $form->ckEditorRow($model,'entry',array('options' => array('id'=>'new title'))),
),
thanks
The last parameter for Controller::widget() is captureOutput which when set to true returns the widget as a string instead of displaying it.
Hi I'm trying to get data from SugarCRM by REST api. It's fine with default module, but with custom module, I got a issue.
I used this example
And getting data from Contacts module which has last name = "abc" is ok with these code:
$get_entry_list_parameters = array(
'session' => $session_id,
'module_name' => 'Contacts',
'query' => "contacts.last_name='abc'",
'order_by' => "",
'offset' => '0',
'select_fields' => array(
'id'
),
'link_name_to_fields_array' => array(
),
'max_results' => '1',
'deleted' => '0',
'Favorites' => false,
);
When I tried to get data from our custom module (eg: Event Session inside Event package), so it's ok as well without Query param like these code
$get_entry_list_parameters = array(
'session' => $session_id,
'module_name' => 'event_event_session',
'order_by' => "",
'offset' => '0',
'select_fields' => array(
'id',
'name'
),
'link_name_to_fields_array' => array(
),
'max_results' => '3',
'deleted' => '0',
'Favorites' => false,
);
But after that I put Query param, I got no record
$get_entry_list_parameters = array(
'session' => $session_id,
'module_name' => 'event_event_session',
'query' => "event_event_session.name='def'",
'order_by' => "",
'offset' => '0',
'select_fields' => array(
'id',
'name'
),
'link_name_to_fields_array' => array(
),
'max_results' => '3',
'deleted' => '0',
'Favorites' => false,
);
I think the way I used to get data from custom module is not correct.
Anyone can help me resolve this issue. Thank you!
Johnny
Are you sure the table name for the custom module is "event_event_session"?
When we create any new custom module using module builder then it is asking for key name. So our module will become as key_modulename. So make sure you are passing the key name along with module name. So that way you can access the data of custom new module.