123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace manager\controllers;
- use yii\sphinx\Query;
- use yii\widgets\ActiveForm;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use manager\models\News;
- //use \app\models\Sphoto;
- use Yii;
- class SphotoController extends BaseController
- {
- public function actionIndex()
- {
- // $model = new Kd();
- // return $this->render('/kd/list', ['model' => $model]);
- }
- public function actionShow($id)
- {
- // $post = Yii::$app->request->get();
- return $this->renderPartial('/default/Showphoto', ['id' => $id]);
- }
- public function actionSearch()
- {
- if( isset( $_GET['search'] ) && trim( $_GET['search'] ) != ''){
- $news_query = (new Query())
- ->from('amic_photo')
- ->select(['id','photo_title'])
- ->andWhere( ['photo_name' => ''])
- ->addOptions(['max_matches' => 200])
- ->addOptions(['field_weights'=> ['photo_title' => 10] ])
- ->match($_GET['search'])
- ->limit(200);
- // ->column();
- $news_query = new Query();
- $sql = "SELECT `id`, `photo_title` FROM `amic_photo` WHERE (MATCH('".$_GET['search']." amic.ru | смолихина | амител"."')) AND (`photo_name`='') LIMIT 200 OPTION max_matches = 200, field_weights = (photo_title = 10)";
- // $command = $news_query->createCommand($sql);
- $command = Yii::$app->sphinx->createCommand($sql);
- // echo $command->getRawSql();
- $items = $command->queryAll();
- $r = array();
- foreach( $items as $item ){
- $r[] = $item;
- }
- return json_encode(['status'=>'ok','data'=>$r]);
- }
- return json_encode(['status'=>'err']);
- }
- }
|