SphotoController.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace manager\controllers;
  3. use yii\sphinx\Query;
  4. use yii\widgets\ActiveForm;
  5. use yii\web\Controller;
  6. use yii\web\NotFoundHttpException;
  7. use manager\models\News;
  8. //use \app\models\Sphoto;
  9. use Yii;
  10. class SphotoController extends BaseController
  11. {
  12. public function actionIndex()
  13. {
  14. // $model = new Kd();
  15. // return $this->render('/kd/list', ['model' => $model]);
  16. }
  17. public function actionShow($id)
  18. {
  19. // $post = Yii::$app->request->get();
  20. return $this->renderPartial('/default/Showphoto', ['id' => $id]);
  21. }
  22. public function actionSearch()
  23. {
  24. if( isset( $_GET['search'] ) && trim( $_GET['search'] ) != ''){
  25. $news_query = (new Query())
  26. ->from('amic_photo')
  27. ->select(['id','photo_title'])
  28. ->andWhere( ['photo_name' => ''])
  29. ->addOptions(['max_matches' => 200])
  30. ->addOptions(['field_weights'=> ['photo_title' => 10] ])
  31. ->match($_GET['search'])
  32. ->limit(200);
  33. // ->column();
  34. $command = $news_query->createCommand();
  35. $items = $command->queryAll();
  36. $r = array();
  37. foreach( $items as $item ){
  38. $r[] = $item;
  39. }
  40. return json_encode(['status'=>'ok','data'=>$r]);
  41. }
  42. return json_encode(['status'=>'err']);
  43. }
  44. }