N
N
Nikita Ronzin2017-04-11 12:09:38
Yii
Nikita Ronzin, 2017-04-11 12:09:38

Why doesn't search work?

The filter stopped working, I can’t understand why and where the error is, I debugged it, and as it turned out, criteria does not receive any data. model

$criteria = new CDbCriteria;

        $criteria->with = array('street' => array('with' => 'town'));
        $criteria->compare('ID', $this->ID);
        $criteria->compare('Town', $this->Street_ID, true);
        $criteria->compare('Surname', $this->Surname, true);
        $criteria->compare('Patronymic', $this->Patronymic, true);
        $criteria->compare('Name', $this->Name, true);
        $criteria->compare('Building', $this->Building);

        $sort = new CSort;
        $sort->attributes = array(
            'street' => array(
                'asc' => 'street,town',
                'desc' => 'Street DESC, Town DESC',
            ),
            '*'
        );
        return new CActiveDataProvider(get_class($this), array(
            'criteria' => $criteria,
            'sort' => $sort,
        ));

controller
public function actionIndex()
    {
        $model = new Fio('search');
        $model->unsetAttributes();  // clear any default values
        if (isset($_GET['Fio']))
            $model->attributes = $_GET['Fio'];

        $dataProvider = new CActiveDataProvider('Fio');
        $this->render('index', array(
            'dataProvider' => $dataProvider,
            'model' => new Fio,
            'phone' => new Phone,
        ));
    }

view
'id' => 'fio-grid',
    'filter' => $model,
    'dataProvider' => $model->search(),
    'columns' => array(
        'Surname',
        'Name',
        'Patronymic',
        array(
            'name' => 'street',
            'value' => function ($data) {
                $output = "";
                if ($data->street instanceof Street) {
                    $output .= $data->street->Street;
                    if ($data->street->town instanceof Town) {
                        $output .= "," . $data->street->town->Town;
                    }
                }
                return $output;
            },
        ),
        'Building',
        array(
            'htmlOptions' => array('nowrap' => 'nowrap'),
            'class' => 'booster.widgets.TbButtonColumn',
        ),
help me understand what is my mistake

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mi7teR, 2017-04-11
@Ababinili

when outputting a render, you override the model. Try

$this->render('index', array(
            'dataProvider' => $dataProvider,
            'model' => $model,
            'phone' => new Phone,
        ));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question