1

В базе данных есть некоторая таблица с сохраненными твитами .

Есть контроллер:

<?php

namespace app\controllers;

use yii\rest\ActiveController;

class TweetController extends ActiveController
{
    public $modelClass = 'app\models\Tweet';
}

Есть соответствующая модель app\model\Tweet созданная в через gii.

В app\web\config добавлено:

..............
    'components' => [
        'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => [
                ['class' => 'yii\rest\UrlRule',
                 'controller' => 'tweet'],
            ],
        ],
        'request' => [
                 'parsers' =>['application/json' => 'yii\web\JsonParser', ],
        ],
...............

В app\web добавлен .htaccess согласно http://www.yiiframework.com/doc-2.0/guide-tutorial-shared-hosting.html

В apache DocumentRoot прописан app\web

Согласно документации: curl -i -H "Accept:application/json" "http://localhost/tweets" должен вернуть постраничный вывод данных модели. Вместо этого:

HTTP/1.1 404 Not Found
Date: Tue, 29 Mar 2016 14:04:05 GMT
Server: Apache/2.4.7 (Ubuntu)
Content-Length: 278
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /tweets was not found on this server.</p>
<hr>
<address>Apache/2.4.7 (Ubuntu) Server at localhost Port 80</address>
</body></html>

Так же пробовался варианта при urlManager 'controller' => ['tw' => 'tweet'] и соответсвующем url.

Почему выдает 404 ошибку? Руководствовался http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html

1
  • Попробуйте так: curl -X GET --header "Accept: application/json" "localhost/tweets". А запрашиваемая страница открывается в браузере?
    – NPreston
    13 июл 2016 в 12:32

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Посмотрите другие вопросы с метками или задайте свой вопрос.