示例#1
0
 /**
  * Manages all models.
  */
 public function actionIndex()
 {
     $model = new Adverts();
     $model->unsetAttributes();
     // clear any default values
     //$model->getData();
     $this->render('index', array('model' => $model));
 }
示例#2
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,
        ));
    }