0
當我試圖搜索的數據我在控制檯此錯誤如何使用Yii2彈性搜索
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'],
],
],
Contorller文件:
<?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'];
}
}
解決你試過以下這一點:https://www.cloudways.com/blog/searching-with-elasticsearch-yii2/ –