Пример #1
0
    public function actionSearch($searchStr = "") {
        $model = new Adverts('search');

        $model->unsetAttributes();  // clear any default values
        //$model->attributes=$_POST;

        if ($searchStr) {
            $model->name = $searchStr;
            $model->text = $searchStr;
        }
        $model->category_id = Yii::app()->request->getParam("cat_id");

        // Обработка дополнительных полей для поиска 
        $s_fields = $_GET['fields'];
        $txt_vld = new textValidator();

        if (is_array($s_fields)) {
            ksort($s_fields);
            foreach ($s_fields as $fn => $fv) {
                if ($fv!=="") {
                    if ($txt_vld->validate_str($fv) and $txt_vld->validate_str($fn)) {
                        if ($model->fields) {
                            $model->fields .= "%";
                        }
                        $model->fields .= '"' . $fn . '"[^"]+"' . $fv . '"';
                    } else {
                        throw new CHttpException(400, ' Bad Request ');
                    }
                }
            }
        }

        $dataProvider = $model->search();

        $this->render('index', array(
            'data' => $dataProvider,
        ));
    }