我想用mongoDB和yii2-advanced模板开发API
。我发现API
与mysql
从api-config集成mongoDB
。但我想用api\config\main.php
创建它。
我在<?php
use \yii\web\Request;
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
$siteUrl = "http://192.168.1.183";
return [
'id' => 'app-api',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'modules' => [
'v1' => [
'basePath' => '@app/modules/v1',
'class' => 'api\modules\v1\Module'
]
],
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => []
],
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => false,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'mongodb' => [
'class' => '\yii\mongodb\Connection',
'dsn' => 'mongodb://localhost/advanced_yii',
],
],
'params' => $params,
];
?>
文件中更改了以下内容:
CountryController.php
在<?php
namespace api\modules\v1\controllers;
use yii\rest\ActiveController;
/**
* Country Controller API
*/
class CountryController extends ActiveController
{
public $modelClass = 'api\modules\v1\models\Country';
public function actionTest()
{
echo "testing";
}
}
?>
档案中:
'http://192.168.1.183/advanced/api/web/v1/test
但是当我在网址中写page not found
时,它会给我stderr
错误。