Exemple #1
0
 public function renderContent()
 {
     $form = new SiteSearchForm();
     if (isset($_POST['LoginForm'])) {
         $form->attributes = $_POST['LoginForm'];
         if ($form->validate()) {
             $this->controller->refresh();
         }
     }
     $this->render('siteSearch', array('form' => $form));
 }
Exemple #2
0
 public function run()
 {
     $form = new SiteSearchForm();
     $form->clearErrors();
     if (isset($_POST['SiteSearchForm'])) {
         $form->attributes = $_POST['SiteSearchForm'];
     }
     if (isset($_POST['SiteSearchForm']) && !$form->validate()) {
         // unset($_POST['SiteSearchForm']);
         $form->clearErrors();
         $form->addError('string', 'Пустое значение поля');
         $z = $form->getErrors();
         // var_dump($z);
         // }
     }
     $this->render('siteSearch', array('form' => $form));
     $form->clearErrors();
 }
 public function actionSearch()
 {
     $search = new SiteSearchForm();
     if (isset($_POST['SiteSearchForm'])) {
         $_POST['SiteSearchForm']['string'] = trim($_POST['SiteSearchForm']['string']);
         //	var_dump($_POST['SiteSearchForm']['string']);
         $search->attributes = $_POST['SiteSearchForm'];
         $_GET['searchString'] = $search->string;
     } else {
         $search->string = $_GET['searchString'];
     }
     if ($search->validate()) {
         //$search->attributes = $_POST['SiteSearchForm'];
         //$_GET['searchString'] = $search->string;
         //} else {
         //$search->string = $_GET['searchString'];
         //$search->validate();
         $criteria = new CDbCriteria(array('condition' => 'tbl_kindparent.kindparent like :keyword  or tbl_inkind.inkind like :keyword or t.name_product like :keyword', 'join' => ' INNER JOIN tbl_inkind on t.id_inkind=tbl_inkind.id_inkind INNER JOIN tbl_kindparent on tbl_kindparent.id_parent=tbl_inkind.id_parent', 'params' => array(':keyword' => '%' . $search->string . '%', ':keyword' => '%' . $search->string . '%', ':keyword' => '%' . $search->string . '%')));
         //var_dump($search->string);
         //$productCount = Product::model()->count($criteria);
         //var_dump($productCount);
         //$pages = new CPagination($productCount);
         //var_dump($pages);
         //$pages->pageSize = 5;
         //$pages->applyLimit($criteria);
         //var_dump($pages->applyLimit($criteria));
         //$product = Product::model()->findAll($criteria);
         //var_dump($product);
         $dataProvider = new CActiveDataProvider('Product', array('pagination' => array('pageSize' => 10), 'criteria' => $criteria));
         $this->render('index', array('dataProvider' => $dataProvider));
         //$this->render('found', array(
         //	'product' => $product,
         //	'pages' => $pages,
         //	'search' => $search,
         //));
     } else {
         //$error=$search->addError('jkhjh');
         //$z=$search->addError('password','Incorrect username or password.');
         //$search->getErrors();
         //var_dump($z);
         //$this->addError('password','Incorrect username or password.');
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     //$this->redirect(array('site/index'));};
     //$this->render('siteSearch', array('form'=>$search));
 }
 /**
  * Sitewide search.
  * Shows a particular post searched.
  */
 public function actionSearch()
 {
     $search = new SiteSearchForm();
     if (isset($_POST['SiteSearchForm'])) {
         $search->attributes = $_POST['SiteSearchForm'];
         $_GET['searchString'] = $search->keyword;
     } else {
         $search->keyword = $_GET['searchString'];
     }
     if ($search->validate()) {
         $criteria = new CDbCriteria();
         $criteria->condition = 'status=' . Post::STATUS_PUBLISHED;
         $criteria->order = 'createTime DESC';
         $criteria->condition .= ' AND contentshort LIKE :keyword';
         $criteria->params = array(':keyword' => '%' . CHtml::encode($search->keyword) . '%');
         $postCount = Post::model()->count($criteria);
         $pages = new CPagination($postCount);
         $pages->pageSize = Yii::app()->params['postsPerPage'];
         $pages->applyLimit($criteria);
         $models = Post::model()->findAll($criteria);
     }
     $this->pageTitle = Yii::t('lan', 'Search Results') . ' "' . CHtml::encode($_GET['searchString']) . '"';
     $this->render('search', array('models' => $models ? $models : array(), 'pages' => $pages, 'search' => $search));
 }