本文整理汇总了PHP中SearchForm::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP SearchForm::getErrors方法的具体用法?PHP SearchForm::getErrors怎么用?PHP SearchForm::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SearchForm
的用法示例。
在下文中一共展示了SearchForm::getErrors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionSearch
public function actionSearch($ihq = null, $iht = null, $status = null)
{
$queryLength = mb_strlen($ihq, 'UTF-8');
// search by hash
$is_hash = false;
if (40 == $queryLength && preg_match('#^[0-9a-f]{40}$#i', $ihq)) {
$is_hash = true;
if ($torrent = Yii::app()->torrentsService->getTorrentByHash($ihq)) {
Yii::app()->request->redirect($torrent->getUrl());
}
}
$this->checkSearchRequest();
if (!empty($iht)) {
if (preg_match('#^\\d$#sui', $iht) && LCategory::getCategoryTag($iht)) {
$iht = LCategory::getCategoryTag($iht);
}
}
if (!empty($ihq)) {
$this->pageTitle = ucfirst($ihq) . ' Torrents Search Results | ' . Yii::app()->name . ' Torrent Search Engine';
} elseif (!empty($iht)) {
$this->pageTitle = mb_convert_case($iht, MB_CASE_TITLE, 'utf-8') . ' Torrents | ' . Yii::app()->name . ' Torrent Search Engine';
}
Yii::app()->getRequest()->getQuery('age');
if (Yii::app()->getRequest()->getQuery('ihs', null) === '1') {
$_GET['popular'] = '1';
}
$searchModel = new SearchForm('simple');
$searchModel->words = $ihq;
$searchModel->tags = $iht;
$searchModel->age = Yii::app()->getRequest()->getQuery('age', 0);
$searchModel->popular = empty($_GET['popular']) ? 0 : 1;
$searchModel->status = empty($status) ? 0 : 1;
$searchModel->validate();
$torrents = new CArrayDataProvider(array());
$totalCount = 0;
if (!$searchModel->getErrors()) {
$torrentModel = LTorrent::model();
$torrents = $torrentModel->getSphinxDataProvider($searchModel);
$totalCount = $torrents->getTotalItemCount();
if (empty($totalCount)) {
$words = explode(' ', $searchModel->words);
if (count($words) > 1) {
$searchModel->words = $words;
$torrents = $torrentModel->getSphinxDataProvider($searchModel);
$totalCount = $torrents->getTotalItemCount();
}
}
}
if (isset($_REQUEST['lucky'])) {
$t = $torrents->getData();
if (count($t)) {
$idx = rand(0, count($t) - 1);
Yii::app()->request->redirect($t[$idx]->getUrl());
}
}
$this->render('list', array('torrents' => $torrents, 'search' => $searchModel->words, 'categoryTag' => $iht, 'categoriesTags' => LCategory::$categoriesTags, 'totalFound' => $totalCount));
}
示例2: actionSearch
/**
* Поиск результатов по параметрам
* @return mixed
*/
public function actionSearch()
{
if ($this->_needRegister()) {
$this->render('needregister');
return;
}
if ((isset($_GET['clean']) || isset($_GET['newsearch'])) && Yii::app()->user->getState('searchdata')) {
// очистить результаты поиска и в раздел "мне нравятся"
Yii::app()->user->setState('searchdata', null, null);
if (isset($_GET['clean'])) {
$this->redirect(array('anketa/mylike'));
} else {
//newsearch
$this->redirect(array('anketa/search'));
}
}
if (isset(Yii::app()->user->searchdata) && !Yii::app()->user->getState('mainsearch')) {
// определить критерии поиска
// echo Yii::app()->user->name;
if (Yii::app()->user->isGuest) {
$model = new Anketa();
//(array('gender'=>''));
} else {
$model = Anketa::model()->findbypk(Yii::app()->user->id);
}
$criteria = $model->getsearchcriteria(Yii::app()->user->searchdata);
$count = Anketa::model()->count($criteria);
$criteria->limit = 2;
$models = Anketa::model()->findAll($criteria);
$this->render('2big', array('models' => $models, 'count' => $count));
} else {
$model = new SearchForm();
Yii::app()->user->setState('mainsearch', 0);
if (Yii::app()->user->hasState('saveddata')) {
$model->attributes = Yii::app()->user->getState('saveddata');
}
if (isset($_POST['SearchForm'])) {
$model->attributes = $_POST['SearchForm'];
if ($model->validate()) {
if (isset($_POST['savedata'])) {
Yii::app()->user->setState('saveddata', $model->attributes);
}
Yii::app()->user->setState('searchdata', $model->attributes);
Yii::app()->user->setState('guestlikes', array());
$this->refresh();
} else {
print_r($model->getErrors());
}
}
$this->render('search', array('model' => $model));
}
}