Change name in CGridView column - yii

I'm trying to change a column name of CGridView.
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'package-days-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
'id',
'package_id',
'description',
array(
'name' => 'My description',
'value' => 'description'
),
array(
'class' => 'CButtonColumn',
),
),
));
?>
I need to add title 'My description' to 'description' column but I'm getting this error
Property "PackageDays.My description" is not defined.

Seems you want change the header not the name try this way
'header'=>'My description',
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'package-days-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
'id',
'package_id',
'description',
array(
'name' => 'description',
'header' = => 'My Description',
// 'value' => 'description' don't need no more
),
array(
'class' => 'CButtonColumn',
),
),
));
?>

Related

Yii ESelect2 extension show preselected valued

i want to show already selected values in tags of ESelected extension but unable to find any solution my code in update form in view is
$this->widget('ext.select2.ESelect2', array(
'name' => 'cat_names[]',
'data' => Coupon::getCategories(),
'options' => array(
'placeholder' => '',
'allowClear' => true,
),
'htmlOptions' => array(
'multiple' => 'multiple',
),
));
if i add tags fields in option of Eselect it changes the behaviour and stop working i add tags in options like this
'tags' => Coupon::getCategories_old(),
Any suggestion will be helpfull thanks in advance
$this->widget('ext.select2.ESelect2', array(
'name' => 'cat_names[]',
'value'=> array(91,95),
'data' => Coupon::getCategories(),
'options' => array(
'placeholder' => '',
'allowClear' => true,
),
'htmlOptions' => array(
'multiple' => 'multiple',
),
));

Cannot do filtering via a dropdown menu in Yii TbGridView (v1.x.x)

I am trying to get the filtering to run although I am having some issues below is my view note that this in in a PARTIAL view :-
If I click on the header of the column it does the sorting as expected, however if I select an option from the dropdown it doesn't filter the items...
Any ideas?
<?php
$myuser = new Myuser('search');
$filterBtn = $this->widget('bootstrap.widgets.TbButton', array(
'icon' => 'filter',
'size' => 'small',
'label' => $myuser->paging ? 'View All' : 'View Less',
'htmlOptions' => array('class'=>'pull-right', 'style'=> 'margin:20px 0;'),
'url' => $myuser->paging ? array('/carrot/myuser/admin/paging/0') : array('/carrot/myuser/admin')
), true);
$this->widget('bootstrap.widgets.TbGridView',array(
'id' => 'myuser-grid','type'=>'striped bordered condensed',
'dataProvider' => $myuser->search(),
'filter' => $myuser,
'columns' => array(
array(
'id' => 'user_id',
'class' => 'CCheckBoxColumn',
'checked' => 'in_array($data->user_id, $this->grid->owner->model->student_ids)',
'checkBoxHtmlOptions' => array(
'name' => 'selected_student_id[]',
)
),
'firstname',
'surname',
'username',
array(
'name' => 'year_id',
'filter' => CHtml::activeDropDownList($myuser, 'year_id', CHtml::listData(Organisation::model()->distinctYears, 'year_id', 'year_id'), array('prompt'=>'All Years')),
'htmlOptions' => array('style' => 'text-align:center;'),
'headerHtmlOptions' => array('style' => 'text-align:left;'),
),
array(
'name' => 'form_name',
'header' => 'Form',
'filter' => CHtml::activeDropDownList($myuser, 'form_name', CHtml::listData(Organisation::model()->distinctForms, 'form_name', 'form_name'), array('prompt'=>'All Forms')),
),
array(
'name' => 'House',
'filter' => CHtml::activeDropDownList($myuser, 'House', CHtml::listData(Organisation::model()->distinctHouses, 'House', 'House'), array('prompt'=>'All Houses')),
),
),
)); ?>
My model has the following search() method:
public function search($limit = false)
{
$criteria = new CDbCriteria();
$criteria->compare('t.user_id',$this->user_id,true);
$criteria->compare('t.firstname',$this->firstname,true);
$criteria->compare('t.surname',$this->surname,true);
$criteria->compare('t.username',$this->username,true);
$criteria->compare('t.year_id',$this->year_id);
$criteria->compare('t.form_name',$this->form_name);
$criteria->compare('t.House',$this->House);
$criteria->compare('o.organisation_id',$this->organisation_id);
$criteria->group = 't.user_id';
$criteria->together = true;
return new CActiveDataProvider($this->currentUserOrganisation(), array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => $this->paging ? ($limit) ? $limit : OverviewController::PAGE_SIZE : 2000
),
'sort' => array(
'defaultOrder' => array('firstname'=>false, 'surname'=>false),
'attributes' => array(
'organisation_name' => array(
'asc' => 'organisation_name',
'desc' => 'organisation_name DESC',
'default' => 'desc',
),
'*'
)
),
));
}
I think you can't use a DropDownList as filter, but you can easily use CHTML::listData():
array(
'name' => 'year_id',
'filter' => CHtml::listData(Organisation::model()->distinctYears, 'year_id', 'year_id'),
'htmlOptions' => array('style' => 'text-align:center;'),
'headerHtmlOptions' => array('style' => 'text-align:left;'),
),
array(
'name' => 'form_name',
'header' => 'Form',
'filter' => CHtml::listData(Organisation::model()->distinctForms, 'form_name', 'form_name'),
),
array(
'name' => 'House',
'filter' => CHtml::listData(Organisation::model()->distinctHouses, 'House', 'House'),
),
This will automatically generate a DropDownList for you.
I hope this works for you.

bootstrap.widgets.TbDetailView, Yii app

Model--
enter code here
public function searchShop()
{
$criteria = new CDbCriteria();
$criteria->compare("name", $this->category, TRUE, "OR");
$criteria->compare("shopname", $this->category, TRUE, "OR");
$criteria->compare("category", $this->category, TRUE, "OR");
return Shops::model()->findAll($criteria);
}
code----
enter code here
<?php
foreach($models as $model):
$this->widget(
'bootstrap.widgets.TbDetailView',
array(
'type'=>'bordered condensed',
'data' => array(
'id' =>array('view', 'id'=>$model->ID),
'Shop Name' => $model->shopname,
'Category' => $model->category,
'ID' => CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID))
),
'attributes' => array(
array('name' => 'Shop Name', 'label' => 'Shop name'),
array('name' => 'Category', 'label' => 'Category'),
array('name' => 'ID', 'label' => 'ID'),
),
)
);
echo "<br><hr><br>";
endforeach;
?>
I want a link on ID by clicking on it it will render view file i.e view.php of shops model
I used CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID)) but it is showing path of that view as 1
help me...
thanks in advance
try
CHtml::link(CHtml::encode($model->ID),
CController::createUrl('site/view',array('id'=>$model->ID)))
here i have assumed that action view lies in site controller. If it lies under some other module name then you can write like this "moduleName/controllerName/actionName"
Edit:
Ok you have to try a few things. TbDetailView extends CDetatilView. Now you can use TbDetailView as
$this->widget(
'bootstrap.widgets.TbDetailView',
array(
'type'=>'bordered condensed',
'data' => array(
'id' =>array('view', 'id'=>$model->ID),
'Shop Name' => $model->shopname,
'Category' => $model->category,
),
'attributes' => array(
array('name' => 'Shop Name', 'label' => 'Shop name'),
array('name' => 'Category', 'label' => 'Category'),
array('label' => 'ID', 'value' => CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID))),
),
)
);
You can also do like
$this->widget(
'bootstrap.widgets.TbDetailView',
array(
'type'=>'bordered condensed',
'data' =>$model,
'attributes' => array(
array('name' => 'shopname', 'label' => 'Shop name'),
array('name' => 'category', 'label' => 'Category'),
array('value' => CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID))
),, 'label' => 'ID'),
),
)
)
;

YiiBooster Navbar target _blank

I am using the navbar of the extension Yiibooster, but I am having problems with a subitem of the menu, I need to go to a new tab, but I can't make it.
<?php $this->widget(
'bootstrap.widgets.TbNavbar',
array(
'brand' => '<img src ="' . Yii::app()->request->baseUrl . '/images/FAVICON.png" />Inicio',
'fixed' => false,
'collapse' => true,
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'items' => array(
array(
'label' => 'Informes',
'items' => array(
array('label' => 'Listado de Activos', 'url' => Yii::app()->baseUrl.'/ZfInmuebles/verpdf',
'itemOptions' => array('target' => '_blank')),
)),
If you want go to blank only in one item of the menu, this is the best option:
'items' => array(
array(
'label' => 'Informes',
'items' => array(
array(
'label' => 'Listado de Activos',
'url' => Yii::app()->baseUrl.'/ZfInmuebles/verpdf',
'linkOptions' => array(
'target' => '_blank'
),
),
),
),
)
Yii CMenu docs: http://www.yiiframework.com/doc/api/1.1/CMenu#items-detail
add class=>'bootstrap.widgets.TbMenu' like
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'submenuOptions' => array('target' => '_blank'),
'items' => array(
array('label' => 'Listado de Activos',
'url' => Yii::app()->baseUrl.'/ZfInmuebles/verpdf',
),
)
)
You need to use $brandOptions:
NavBar::begin([
'brandLabel' => 'Label text',
'brandUrl' => '/'.Yii::$app->homeUrl,
'brandOptions' => [
'target'=>'_blank'
],
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);

Yii customize CGridView Items template

I am using Yii with bootstrap features;
So, I have changed the container tagName from div to table;
Now, the table with the items class is inside the table with table class;
The template property defines my issue;
How do I add the following class : table table-striped table-hover to the table with items class?
the tables structure is:
<table class="table">
<tr>
<td>
<table class="items">
...
{items} generates the <table class="items"> table
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'orders-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'ajaxUrl' => Yii::app()->baseUrl . '/orders/admin',
'tagName' => 'table',
'htmlOptions' => array(
'class' => 'table',
'style' => 'width:auto;',
'align' => 'left',
),
'cssFile' => Yii::app()->baseUrl . '/css/custom.css',
'template' =>
'<tr><td style="border-top:none;height:74px;">{pager}</td></tr>' .
'<tr><td style="height:34px;border-top:none;">{summary}</td></tr>' .
'<tr><td>{items}</td></tr>' .
'<tr><td style="border-top:none;">{summary}</td></tr>' .
'<tr><td style="border-top:none;height:74px;">{pager}</td></tr>',
'columns' => array(
array(
'header' => 'Order ID',
'name' => 'id',
'type' => 'raw',
'value' => 'CHtml::link(str_pad($data->id, 9, "0", STR_PAD_LEFT),array("update","id"=>$data->id))',
),
array(
'header' => 'Name',
'name' => 'var_user_full_name',
'value' => '$data->UserFullName',
'filter' => CHtml::activeTextField($model, 'var_user_full_name'),
),
array(
'name' => 'total_price',
'type' => 'raw',
'value' => 'CurrencyData::$_currency[$data->currency]." ".$data->total_price',
),
array(
'name' => 'created',
'value' => 'date("d/m/Y",$data->created)',
'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $model,
'attribute' => 'created',
'language' => 'en-AU',
// 'i18nScriptFile' => 'jquery.ui.datepicker-en.js',
'htmlOptions' => array(
'id' => 'datepicker_for_due_date',
'size' => '10',
),
'defaultOptions' => array(
'showOn' => 'focus',
'dateFormat' => 'dd/mm/yy',
'showOtherMonths' => true,
'selectOtherMonths' => true,
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
)
), true),
),
array(
'name' => 'active',
'header' => 'Status',
'value' => 'OrdersData::$active[$data->active]',
//'filter' => OrdersData::$active,
'filter' => CHtml::activeDropDownList($model, 'active', OrdersData::$active, array('prompt' => '-Select-')),
),
array(
'class' => 'CButtonColumn',
'header' => 'Action',
'template' => '{update}',
),
),
));
?>
found it:
'itemsCssClass' => 'table table-striped table-hover',