Hi All,
I currently have a Yii 1.x web app and I would like to implement a search feature using popular elasticsearch.
To my knowledge, I know Yii 2.0 has already an established yii-elasticsearch extension and I have tried it using Yii 2.0 basic web app and find that it is useful and I am thinking how can I deploy it into Yii 1.x app?
I managed to make both Yii 1.x and Yii 2.x app running at the same time following the instruction at tutorial here.
The integration looks fine and I created a SearchController and a Search model object at Yii 1.x.
Search Controller
use search\models\Customer;
class DefaultController extends Controller
{
/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl',
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow',
'actions'=>array('index'),
'users'=>array('*'),
),
//default deny all users anything not specified
array('deny',
'users'=>array('*'),
),
);
}
/**
* This action shows search index page
*/
public function actionIndex()
{
$matchQuery = ["match" => ["name" => "Test Name"]];
$result = Customer::find()->query($matchQuery)->all();
return $this->render('index',['result'=>$result]);
}
}
Customer search model
namespace search\models;
class Customer extends \yii\elasticsearch\ActiveRecord
{
/**
* @return array the list of attributes for this record
*/
public function attributes()
{
// path mapping for '_id' is setup to field 'id'
return ['id', 'name'];
}
}
When I try to access the controller via route "search/index" (my main app is Yii 1.x still), I get following error:
PHP Fatal Error – yii\base\ErrorException
Class ‘yii\elasticsearch\ActiveRecord’ not found
I know the reason likely is caused by namespace problem or unable to find yii2 classes.
Any body has idea how to resolve this one?
Many thanks !!