Faced the following problem. There is a form

<?php $form = ActiveForm::begin([ 'id' => 'search-form', 'action' => 'site/search', 'method' => 'get', 'enableClientValidation' => false, 'enableAjaxValidation' => false ])?> <?= $form->field($searchModel, 'request')->label(false)->textInput(['placeholder' => 'Search', 'size' => 12]) ?> <?php ActiveForm::end() ?> 

sending the form I get to http://yii.loc/site/search?Search%5Brequest%5D=my_request I’m interested in what Search%5Brequest%5D how it is formed and how I format the URL to http://yii.loc/site/search?search=my_request

1 answer 1

Search%5Brequest%5D = Search[request]

  • Search - model name

  • request - the name of the field in the model

This name forms the ActiveForm::field() method for the input field (in this case)

To change the name, pass the name parameter to the options array of the textInput() method

->textInput(['placeholder' => 'Search', 'size' => 12, 'name'=>'search'])

Or use Html :: textInput ()

Html::textInput('search', $searchModel->request, ['placeholder' => 'Search', 'size' => 12])