1

I have DocumentSearch model (that extends Document model) in Yii2. When I search, $_GET params are like /index.php?DocumentSearch[id]=4&DocumentsSearch[name]=Test

Q: How to replace DocumentSearch[id] param into id and all other attributes? I don't like this way

sirjay
  • 1,767
  • 3
  • 32
  • 52
  • 2
    Haven't done this before, but you could try to override the formName() method of your DocumentSearch model, returning an empty string http://www.yiiframework.com/doc-2.0/yii-base-model.html#formName()-detail – MacGyer Apr 11 '16 at 18:54
  • check this: http://stackoverflow.com/questions/25522462/yii2-rest-query/30560912#30560912 – Salem Ouerdani Apr 11 '16 at 21:30

1 Answers1

1

As MacGyer said in its comment, you should simply override formName() :

public function formName()
{
    return '';
}

Read more about formName() :

The form name is mainly used by yii\widgets\ActiveForm to determine how to name the input fields for the attributes in a model. If the form name is "A" and an attribute name is "b", then the corresponding input name would be "A[b]". If the form name is an empty string, then the input name would be "b".

soju
  • 25,111
  • 3
  • 68
  • 70