Yii Pager没有按预期工作

时间:2014-01-06 09:53:54

标签: php .htaccess yii yii-extensions

我正在使用Yii框架,而且我遇到了与Pager小部件结合使用bootstrap.widgets.TbGridView小部件的问题。

(请注意我是Yii的新手 - 所以我可以随意指出任何明显的错误)

所有过滤都运行正常,但是当我从“已实现”下拉菜单中选择任何选项时,它会更改寻呼机的网址结构。

例如,默认情况下,当我在Firebug中查看寻呼机链接时,URL如下所示:

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

然而,一旦我从'Fulfilled'下拉列表中做出选择,并尝试再次使用寻呼机它就不再有效,并且在通过Firebug检查后​​,寻呼机链接已经发生了巨大变化:

<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>

我希望URL保留与上面的初始链接非常相​​似的结构。

以下是页面的视图代码

<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>

提前致谢 - 请记住我是Yii的新手

...更新 我检查了Firebug日志,可以看到GET请求失败(因为它显示在Firebug日志中的RED文本中) 网址是:

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

一旦它尝试调用此“失败”的URL,寻呼机就会停止工作,直到我进行页面刷新(例如F5)并返回其默认的寻呼机设置。

更新2 ... 由于某种原因直接加载到地址浏览器中的失败URL将自动尝试添加“www”。在URL的开头,所以完整的URL现在看起来像这样..

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

这可能与我的本地htaccess文件有关(这个问题似乎不存在于我们的'实时'版本的应用程序中。

1 个答案:

答案 0 :(得分:0)

我必须在Yii中使用“删除过滤器”的一些功能才能实现这一功能 - 不久将发布一些代码。