Yii2弹性搜索使用方法
How to use Yii2 elastic search
当我尝试搜索数据时,控制台出现此错误
PHP Notice 'yii\base\ErrorException' with message 'Use of undefined constant CURLOPT_USERAGENT - assumed 'CURLOPT_USERAGENT'' in /var/www/megamart/vendor/yiisoft/yii2-elasticsearch/Connection.php:320
我不明白这是什么问题
这是我的控制和模型
配置文件:
'elasticsearch' => [
'class' => 'yii\elasticsearch\Connection',
'nodes' => [
['http_address' => '127.0.0.1:9200'],
],
],
控制器文件:
<?php
namespace frontend\controllers;
use frontend\models\elastic\User;
use yii\web\Controller;
use Yii;
use yii\helpers\VarDumper;
class ElasticController extends Controller{
public function actionTest(){
if(Yii::$app->request->isAjax){
$params = $_POST['q'];
$query = User::find()->where(['username' => 'admin'])->one();
VarDumper::dump($query,6,1);
}
}
}
模型文件:
<?php
namespace frontend\models\elastic;
class User extends \yii\elasticsearch\ActiveRecord
{
public function attributes()
{
return ['id', 'username', 'address'];
}
}
通过安装这个
解决了
sudo apt-get install php5-curl
当我尝试搜索数据时,控制台出现此错误
PHP Notice 'yii\base\ErrorException' with message 'Use of undefined constant CURLOPT_USERAGENT - assumed 'CURLOPT_USERAGENT'' in /var/www/megamart/vendor/yiisoft/yii2-elasticsearch/Connection.php:320
我不明白这是什么问题 这是我的控制和模型 配置文件:
'elasticsearch' => [
'class' => 'yii\elasticsearch\Connection',
'nodes' => [
['http_address' => '127.0.0.1:9200'],
],
],
控制器文件:
<?php
namespace frontend\controllers;
use frontend\models\elastic\User;
use yii\web\Controller;
use Yii;
use yii\helpers\VarDumper;
class ElasticController extends Controller{
public function actionTest(){
if(Yii::$app->request->isAjax){
$params = $_POST['q'];
$query = User::find()->where(['username' => 'admin'])->one();
VarDumper::dump($query,6,1);
}
}
}
模型文件:
<?php
namespace frontend\models\elastic;
class User extends \yii\elasticsearch\ActiveRecord
{
public function attributes()
{
return ['id', 'username', 'address'];
}
}
通过安装这个
解决了sudo apt-get install php5-curl