I want to change the name of the form field from Page[body] to body lets say. Following is the code for WYSIWYG editor.
<?php echo $form->field($model, 'body')->widget(
\yii\imperavi\Widget::className(),
[
'plugins' => ['fontcolor', 'video'],
'options'=>[
'minHeight'=>400,
'maxHeight'=>400,
'buttonSource'=>true,
//'imageUpload'=>Yii::$app->urlManager->createUrl(['/file-storage/upload-imperavi'])
]
]
) ?>
I don't want to change my model just the name of the form field submitted as the filed is submitted to remote API.
For normal fields i do <?php echo $form->field($model, 'name')->textInput(['name' => 'name']) ?>
In the options you could assign an your name value
<?php echo $form->field($model, 'body',
[ 'options' => [ 'name' => 'your_name']])->widget(
\yii\imperavi\Widget::className(),
[
'plugins' => ['fontcolor', 'video'],
'options'=>[
'minHeight'=>400,
'maxHeight'=>400,
'buttonSource'=>true,
//'imageUpload'=>Yii::$app->urlManager->createUrl(['/file-storage/upload-imperavi'])
]
]
) ?>
Thank you guys this worked.
<?php
echo yii\imperavi\Widget::widget([
// You can either use it for model attribute
'model' => $model,
'attribute' => 'body',
// or just for input field
//'name' => 'body',
'htmlOptions'=>[
'name'=>'body',
],
// Some options, see http://imperavi.com/redactor/docs/
'options' => [
'toolbar' => false,
],
]);
?>
and this also
<?php echo $form->field($model, 'body',
[ 'options' => [ 'name' => 'body']])->widget(
\yii\imperavi\Widget::className(),
[
'plugins' => ['fontcolor', 'video'],
'htmlOptions'=>['name'=>'body'],
'options'=>[
'minHeight'=>400,
'maxHeight'=>400,
'buttonSource'=>true,
//'imageUpload'=>Yii::$app->urlManager->createUrl(['/file-storage/upload-imperavi'])
]
]);?>
Related
It is necessary that in the field listBoxt, there was a placeholder, something like "Select a role for the user", i.e. message that the user sees without selecting anything in the listbox. But this should include the option 'prompt' => 'remove the role' so that the user can remove the role through the drop-down list.
Is it possible to do this through the standard Yii functional without resorting to JS?
echo $form->field($model, 'additionalRoles', [
'options' => [
'class' => 'form-group',
],
])->listBox($additionalRoles, [
'class' => 'form-control j-multi-select2',
'prompt' => 'Select additional role',
]);
For example: https://jsfiddle.net/8e7avn2d/1/
<?=
$form->field($model, 'additionalRoles', [
'options' => [
'class' => 'form-group',
],
])
->listBox($additionalRoles, [
'class' => 'form-control j-multi-select2',
'prompt' => [
'text' => "Select additional role",
'options' => [
'disabled' => true,
'selected' => true,
'hidden' => true,
]]
]);
?>
to achieve your example you should use dropDownList instead of listBox
echo $form->field($model, 'additionalRoles', [
'options' => [
'class' => 'form-group',
],
])->dropDownList($additionalRoles, [
'class' => 'form-control j-multi-select2',
'prompt' => 'Select additional role',
]);
i am trying to use kartik export and its not working for me. In config file I have added following code:
'modules' => [
'gridview' => [
'class' => '\kartik\grid\Module',
],
],
In Composer i have added folowing code
"kartik-v/yii2-export": "#dev",
"kartik-v/yii2-mpdf":"#dev",
"kartik-v/yii2-grid": "#dev"
My view code is like this:
<?php
use yii\helpers\Html;
use kartik\grid\GridView;
use yii\bootstrap\Tabs;
use kartik\export\ExportMenu;
use yii\widgets\Pjax;
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="general-info-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php
<p>
<?= Html::a('create', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php
$gridColumns = [
'sfcl_name',
[
'attribute'=> 'org_type',
'value' => 'orgType.cv_lbl'
],
];
echo ExportMenu::widget([
'dataProvider' => $dataProvider,
'columns' => $gridColumns
]);
?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'pjax'=>true,
'columns' => [
'sfcl_name',
'phone',
[
'attribute'=>'regd_dt_ad',
'format'=>['date', 'php:Y-M-d'],
'xlFormat'=>'mmm\-dd\, yyyy', // different date format
'width'=>'100px'
],
[
'attribute'=> 'org_type',
'value' => 'orgType.cv_lbl'
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
My controller code is:
My controller code to call this view : public function actionIndex()
{
$searchModel = new SfclGeneralSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
On click of export menu nothing is happening.In tutorial i saw there were options for exporting to pdf ,html,csv,json,text.such options doesnot appers in my case.Is the css not working or what?
you run "composer update" command?.
also in your web.php
'modules' => [
'gridview' => [
'class' => '\kartik\grid\Module',
],
],
add the property downloadAction, like this:
'modules' => [
'gridview' => [
'class' => '\kartik\grid\Module',
'downloadAction' => 'gridview/export/download',
]
],
How to set value for DetailView. I am trying by set value gridview way but that just show error result
This is the code i wrote
<?php echo DetailView::widget([
'model' => $model,
'attributes' => [
'username',
'email',
[ 'label' => 'Nama',
'value' => function($model) { return $model->first_name ." ". $model->last_name; },
],
],
]); ?>
The error is :
htmlspecialchars() expects parameter 1 to be string, object given
In DetailView no need to use function in value property.
<?php echo DetailView::widget([
'model' => $model,
'attributes' => [
'username',
'email',
[ 'label' => 'Name',
'value' => $model->first_name ." ". $model->last_name,
],
],
]); ?>
I have used:
echo AutoComplete::widget([
'name' => 'file',
'clientOptions' => [
'source' => ['USA', 'RUS'],
],
]);
But I get the error:
Class 'AutoComplete' not found.
You should install Yii 2 Jquery UI extension first.
The full class name with namespace is yii\jui\Autocomplete.
You can use it like this:
use yii\jui\Autocomplete;
...
echo AutoComplete::widget([
'name' => 'file',
'clientOptions' => [
'source' => ['USA', 'RUS'],
],
]);
or
echo yii\jui\AutoComplete::widget([
'name' => 'file',
'clientOptions' => [
'source' => ['USA', 'RUS'],
],
]);
I am trying to render an Image in view file. My code is like below:
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'name',
//'photo',
[
'attribute'=>'photo',
'value'=>('<img src =' .'uploads/' . $model->photo . ' height="100" width="100"' . '>')
],
[
'attribute' => 'birth_date',
'format' => ['date', 'dd-MM-Y'],
],
'mobile',
],
]) ?>
Though the code below works:
<?php echo ('<img src =' .'uploads/' . $model->photo .'>'); ?>
Thanks.
Try this:
[
'attribute'=>'photo',
'value'=>$model->photo,
'format' => ['image',['width'=>'100','height'=>'100']],
],
DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'photo:image',
],
])
[
'attribute'=>'group_pic',
'value'=>('uploads/group_pro_pic/' . $model->group_pic),
'format' => ['image',['width'=>'230','height'=>'200']],
]
Try this:
[
'attribute'=>'images',
'value'=> Yii::$app->homeUrl.'uploads/'.$model->images,
'format' => ['image',['width'=>'100','height'=>'100']],
],
Try this
[
'attribute' => 'vUpload',
'value'=>'uploads/' .$model->vUpload,
'format' => ['image',['width'=>'100','height'=>'100']],
],
[
'attribute'=>'profile',
'value'=>'../uploads/' .$model->profile,
'format' => ['image',['width'=>'100','height'=>'100']],
],