Yii2 - How to sort the gridview on a [POST] form without losing the filters using arrayDataProvider

0

I have a form with 14 search fields and half of these fields are arrays, so the form's method is POST otherwise it displays error

  

(414 - Request URI too long).

I am using gridview to render results with pagination = 10 , but when I click to show the results of the second% _co_de% Yii2 can not interpret the request and all results they get lost. I have noticed that gridview uses the default method of the gridview method it loses itself and "adds" to the results.

The same happens when I try to use GET . I need to sort and use gridview with the POST form.

    
asked by anonymous 14.12.2018 / 19:35

1 answer

0

[RESOLVED] To shorten the URL and get use of the GET method I used the following code:

class MyModelExemple extends ActiveRecord 
{
    private $_formName;

    // Função que vai "renomear" a model
    public function formName()
    {
        if (!empty($this->_formName)) {
            return $this->_formName;
        } else {
            return parent::formName();
        }
    }

    // Função que vai setar o "nome temporário" da model
    public function setFormName($formName)
    {
        if (!empty($formName)) {
            $this->_formName = $formName;
        }
    }
}

CONTROLLER:

public function actionIndex()
{
    //Instanciando a model
    $modelExempleInstancied = new MyModelExemple();
    //Setando o nome temporário para a model = A
    $modelExempleInstancied->setFormName('A');

    /* Todo seu código */

    return $this->render($view, [
                'dataProvider' => $dataProvider,
                'model'        => $modelExempleInstancied
    ]);       
}

When the model is passed to view it will be rendered with the name 'A', without renaming the model the field name would be 'MyModelExemple [FieldName]' but now the field is named 'A [FieldName] so my URL is much smaller and I have no problems with (414 - Request URI too long).

    
18.12.2018 / 12:07