<?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();
				$command = $news_query->createCommand();
				$items = $command->queryAll();
				$r = array();
				foreach( $items as $item ){
					$r[] = $item;
				}
				return json_encode(['status'=>'ok','data'=>$r]);
			}
		return json_encode(['status'=>'err']);
    }

}
