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

Asked

Viewed 105 times

0

I have a form with 14 search fields and half of these fields are arrays, for this reason the form method is POST otherwise shows error

(414 - Request URI Too long).

I’m using the gridview to render results with paging = 10, but when I click to show the results of the second tab of gridview Yii2 cannot interpret the request and all results are lost. I noticed that the gridview uses by default the framework method GET that he gets lost and "disappears" with the results.

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

1 answer

0

[RESOLVED] To shorten the URL and be able to use 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 has the name "A[Fieldname]", so my URL is much smaller and I have no problems (414 - Request URI Too long).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.