【问题标题】:Yii2 search linkYii2 搜索链接
【发布时间】:2018-07-19 07:16:46
【问题描述】:

在 Yii2 我有这样的搜索链接:localhost/project/web/?ItemSearch%5Btitle%5D=star

如何将其更改为:localhost/project/web/?title=star

这是我的表格

<?= $form->field($model, 'title') ?>

它看起来像这样

<input type="text" name="ItemSearch[title]">

当我尝试将其更改为:

<input type="text" name="title">

搜索不起作用,但链接看起来不错。

你知道怎么做吗?

【问题讨论】:

  • 您在使用GridView 搜索表单吗?

标签: php forms search hyperlink yii2


【解决方案1】:

您需要覆盖模型的 formName 方法以返回空字符串
本质上,它会从您的输入(使用此模型的所有输入)的 name 属性中跳过模型名称

class ItemSearch extends Model
{
    public function formName() {
        return '';
    }
}

【讨论】:

    猜你喜欢
    • 2016-03-24
    • 1970-01-01
    • 1970-01-01
    • 2018-08-10
    • 2016-03-26
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 2016-05-20
    相关资源
    最近更新 更多