我正在尝试按照指南中的描述实现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) 我的餐桌有约.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)
我以为我把正确的东西编入索引; 桌子太大了?有没有人建议如何更快地从这个表中获取信息?