質問

I am using the Yii Framework, and I'm having issues with the bootstrap.widgets.TbGridView widget in conjunction with the Pager widget.

(Please note that I am new to Yii - so feel free to point out any obvious mistakes on my behalf)

All the filtering works fine, however when I select any option from the 'Fulfilled' dropdown menu it changes the URL structure of the Pager.

For instance, by default when I view the Pager links in Firebug the URL looks like this:

<a href="/mysite/shop/purchases/admin/ajax/shoppurchases-grid/ShopPurchases_sort/user.form_name/ShopPurchases_page/3">3</a>

However once I make a selection from the 'Fulfilled' dropdown, and try to use the Pager again it no longer works, and after inspecting it via Firebug the Pager links have all changed dramatically to this:

<a href="/mysite/shop/purchases/admin/ShopPurchases%5BfilterProductName%5D//ShopPurchases%5BfilterUserName%5D//ShopPurchases%5BfilterFormName%5D//ShopPurchases%5BfilterFirstName%5D//ShopPurchases%5Bprice%5D//ShopPurchases%5Bpurchase_time%5D//ShopPurchases%5Bfulfilled%5D//ShopPurchases_page/3/ajax/shoppurchases-grid/ShopPurchases_sort/user.form_name">3</a>

I would expect the URL to retain a very similar structure as the initial link above.

Below is the view code for the page

<div class="row-fluid">
<div class="inner">
    <?php $this->widget('bootstrap.widgets.TbGridView',array(
'id'            => 'shoppurchases-grid',
'type'          => 'striped bordered condensed',
'dataProvider'  => $model->setPurchaseType('school')->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")
    ),
),
)); ?>
</div>

Thanks in advance - please remember I'm new to Yii

update... I've checked the Firebug log and can see the GET request is failing (as it shows up in RED text in the Firebug log) The URL is :

http://mysite.local/site/shop/purchases/admin/ShopPurchases%5BfilterProductName%5D//ShopPurchases%5BfilterUserName%5D//ShopPurchases%5BfilterFormName%5D//ShopPurchases%5BfilterFirstName%5D//ShopPurchases%5Bprice%5D//ShopPurchases%5Bpurchase_time%5D//ShopPurchases%5Bfulfilled%5D/0/ajax/shoppurchases-grid/ShopPurchases_sort/price?ajax=shoppurchases-grid

Once it tries to call this 'failed' URL the Pager stops working until I do a page refresh (e.g F5) and it returns to its default pager settings.

update 2... The failed URL when loaded directly into the address browser for some reason will automatically attempt to add 'www.' at the start of the URL so the full url now looks like this..

http://wwwmysite.local/site/shop/purchases/admin/ShopPurchases[filterProductName]//ShopPurchases[filterUserName]//ShopPurchases[filterFormName]//ShopPurchases[filterFirstName]//ShopPurchases[price]//ShopPurchases[purchase_time]//ShopPurchases[fulfilled]/0/ShopPurchases_page/2/ajax/shoppurchases-grid?ajax=shoppurchases-grid

Is this something possibly related to my local htaccess file (this problem doesn't seem to exist on our 'live' version of the app.

役に立ちましたか?

解決

I had to use some functionality to 'Remove Filters' in Yii for this to work - will post some code shortly.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top