小编dat*_*lls的帖子

如何解决此Yii2 RESTful Web服务API路由错误?

我正在尝试按照指南中的描述实现Yii2 RESTful Web服务API.我正在尝试使用高级应用程序模板.问题很简单,当我尝试访问服务时,我得到的只是404错误.我想开始尝试一些简单的事情,所以我只是想使用一个国家表和相关的ActiveRecord类来试试它,这里是代码:

这是在frontend/config/main.php中的组件配置中:

    'urlManager' => [
        'enablePrettyUrl' => true,
        'enableStrictParsing' => true,
        'showScriptName' => false,
        'rules' => [
            ['class' => 'yii\rest\UrlRule', 'controller' => 'country'],
        ],
    ],
    'request' => [
        'parsers' => [
            'application/json' => 'yii\web\JsonParser',
        ]
    ]
Run Code Online (Sandbox Code Playgroud)

这是frontend/controllers/CountryController.php中的代码:

namespace frontend\controllers;

use yii\rest\ActiveController;

class CountryController extends ActiveController
{
    public $modelClass = 'common\models\Country';
}
Run Code Online (Sandbox Code Playgroud)

像国家这样的所有ActiveRecord模型都是共同的/模型.

我使用以下方法来尝试:

curl -i -H "Accept:application/json" "http://myfrontendapp.loc/country"
Run Code Online (Sandbox Code Playgroud)

这是我得到的输出:

HTTP/1.1 404 Not Found
Date: Fri, 31 Oct 2014 22:46:50 GMT
Server: Apache
Content-Length: 205
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE …
Run Code Online (Sandbox Code Playgroud)

rest yii2

2
推荐指数
1
解决办法
5477
查看次数

我该如何进一步优化?

我的餐桌有约.121,246,211行.记录是简单的页面印象信息.

这是架构:

create table stat_page
(
  id int auto_increment primary key,
  pageId int not null,
  timestamp int not null
)
  collate = utf8_unicode_ci;

create index pageIdIndex
  on stat_page (pageId);

create index timestampIndex
  on stat_page (timestamp);
Run Code Online (Sandbox Code Playgroud)

此查询需要15秒:

select count(*)
from stat_page
where `timestamp` > 1543622400;
Run Code Online (Sandbox Code Playgroud)

此查询需要将近7分钟:

select count(*)
from stat_page
where `timestamp` > 1543622400
and pageId = 87;
Run Code Online (Sandbox Code Playgroud)

我以为我把正确的东西编入索引; 桌子太大了?有没有人建议如何更快地从这个表中获取信息?

mysql sql

2
推荐指数
1
解决办法
64
查看次数

标签 统计

mysql ×1

rest ×1

sql ×1

yii2 ×1