Roboto6_1on
Roboto6_1on

Reputation: 315

Yii2 search link

In Yii2 I have search link like this: localhost/project/web/?ItemSearch%5Btitle%5D=star

How can I change it to: localhost/project/web/?title=star?

This is my form

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

and it looks like this

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

when I tried to change it to:

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

search doesn't work but link looks good.

Do you have any idea how to make it?

Upvotes: 0

Views: 73

Answers (1)

csminb
csminb

Reputation: 2382

you need to override the formName method of your model to return an empty string
essentially it will skip the model name from the name property of your inputs (all inputs where you use this model)

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

Upvotes: 1

Related Questions