我遇到了Yii的问题(使用1.1.x),我正在使用TbGridView来显示带过滤&的自举网格视图。寻呼。
然而,当我从“满足”中选择时,它可以正常工作。当我尝试使用寻呼机(例如,转到页面记录集的第2页)时,(是,否或全部)下拉列表,它不会保留此信息并且已经完成了#39;我选择的选项。 因此,例如,如果我选择了“不”。在已完成的下拉列表中,然后使用寻呼机,它不会保留“否”。由于某种原因,下拉菜单中的值
任何人都可以提出任何想法,因为我完全迷失了 - 尽管我认为它与我的模特功能有关吗?
<?php $this->widget('bootstrap.widgets.TbGridView',array(
'id' => 'shoppurchases-grid',
'type' => 'striped bordered condensed',
'dataProvider' => $model->setPurchaseType('org')->search(10),
'filter' => $model,
'template' => '{summary}{items}{pager}',
'columns' => array(
array(
'header' => 'Product Image',
'value' => 'CHtml::image($data->product->displayImageUrl, $data->product->product_name, array("class"=>"grid-image"))',
'type' => 'raw',
),
array(
'header' => 'Product',
'name' => 'product.product_name',
'value' => '$data->product->product_name',
'filter' => CHtml::activeTextField($model, 'filterProductName', array('placeholder' => 'filter by product name')),
'type' => 'raw',
),
array(
'header' => 'Username',
'name' => 'user.firstname',
'value' => '($data->user instanceof MyUser) ? CHtml::link(CHtml::encode($data->user->username),array("/carrot/myuser/update","id"=>$data->user->user_id)) : ""',
'filter' => CHtml::activeTextField($model, 'filterUserName', array('placeholder' => 'filter by username')),
'type' => 'raw'
),
array(
'header' => 'Form Name',
'name' => 'user.form_name',
'value' => '($data->user instanceof MyUser) ? $data->user->form_name : ""',
'filter' => CHtml::activeTextField($model, 'filterFormName', array('placeholder' => 'filter by form name')),
'type' => 'raw'
),
array(
'header' => 'Student',
'name' => 'user.username',
'value' => '($data->user instanceof MyUser) ? $data->user->fullname : ""',
'filter' => CHtml::activeTextField($model, 'filterFirstName', array('placeholder' => 'filter by first name')),
'type' => 'raw'
),
array(
'header' => 'Price',
'name' => 'price',
'filter' => BHtml::activeCompareableTextField($model, 'price', array('placeholder' => 'filter by price')),
'type' => 'raw'
),
array(
'header' => 'Purchase Time',
'name' => 'purchase_time',
'value' => 'app()->dateFormatter->format("dd/MM/y H:m:s", $data->purchase_time)',
'filter' => BHtml::activeCompareableDateRange($model, 'purchase_time', array('placeholder' => 'filter by purchase time')),
'type' => 'raw'
),
array(
'header' => 'Fulfilled',
'name' => 'fulfilled',
'value' => user()->hasAuth(Group::READ_ONLY, "equal") ? '$data->fulfilled ? "Yes" : "No"' : 'CHtml::activeCheckBox($data, "fulfilled")',
'filter' => CHtml::activeDropDownList($model, 'fulfilled', array(0 => 'No', 1 => 'Yes'), array('prompt' => 'All')),
'type' => 'raw',
'htmlOptions' => array('class' => 'align-center'),
'headerHtmlOptions' => array('class' => 'align-center'),
),
array(
'name' => 'organisation_name',
'visible' => ((user()->hasAuth(Group::GROUP_ADMIN, 'equal')) && (!user()->hasState('view_org'))),
'filter' => CHtml::activeDropDownList($model, 'organisation_id', CHtml::listData(Organisation::model()->leaChildren, 'organisation_id', 'organisation_name'), array('prompt'=>'All Schools')),
),
array(
'header' => '',
'value' => 'CHtml::link("Refund", Yii::app()->controller->createUrl("bulk",array("id"=>$data->primaryKey)), array("class" => "btn btn-save", "name" => CHtml::activeName($data,"refunded")))',
'type' => 'raw',
'visible' => !user()->hasAuth(Group::READ_ONLY, "equal")
),
),
)); ?&GT;
//型号
public function search() {
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria = new CDbCriteria;
$criteria->with = array('user', 'product');
$criteria->compare('t.purchase_id', $this->purchase_id);
$criteria->compare('t.user_id', $this->user_id, true);
$criteria->compare('t.price', $this->price);
$criteria->compare('t.form_price', $this->form_name);
$criteria->compare('t.GUID', $this->GUID, true);
$criteria->compare('t.refunded', $this->refunded);
$criteria->compare('user.organisation_id', $this->organisation_id);
ActiveRecord::addDateRange($criteria, 't.purchase_time', $this->purchase_time, false);
if (strlen($this->fulfilled) > 0)
$criteria->addCondition('fulfilled ' . (($this->fulfilled == 1) ? "IS NOT NULL" : "IS NULL"));
//Related fields filtering
$criteria->compare('product.product_name', $this->filterProductName, true);
$criteria->compare('user.username', $this->filterUserName, true);
$criteria->compare('user.firstname', $this->filterFirstName, true);
$criteria->compare('user.form_name', $this->filterFormName, true);
return new CActiveDataProvider($this->currentUserOrganisation(), array(
'criteria' => $criteria,
'sort' => array(
'defaultOrder' => 't.purchase_time DESC',
'attributes' => array(
'organisation_name' => array('asc' => 'o.organisation_name', 'desc' => 'o.organisation_name DESC'),
'user.username' => array('asc' => 'user.username', 'desc' => 'user.username desc'),
'user.form_name' => array('asc' => 'user.form_name', 'desc' => 'user.form_name desc'),
'user.firstname' => array('asc' => 'user.firstname', 'desc' => 'user.firstname desc'),
'product.product_name' => array('asc' => 'product.product_name', 'desc' => 'product.product_name desc'),
'*'
)
)
));
}
答案 0 :(得分:0)
这是因为你的实现值是0,有时当你将0传递给php时。它会把它当作假的。
如果可能,请在视图页面中进行如下设置
array('no' => 'No', 'yes' => 'Yes')
然后你也需要改变模型。
$criteria->addCondition('fulfilled ' . (($this->fulfilled == 'yes') ? "IS NOT NULL" : "IS NULL"));