yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

REST apis suddenly giving error 404 in yii2.0.40 #19502

Closed abayomiabayomi closed 2 years ago

abayomiabayomi commented 2 years ago

I have been running my Yii 2.0.40 app without issues. It has worked well. Recently, without any upgrade or update on, It just started giving a consistent "Not Found (#404). Page not found" error. This issue occurs both on my local server and web server

What steps will reproduce the problem?

calling the api here http://localhost/gig_books/backend/web/index.php/api/

What is the expected result?

It displays the requested content in json format

What do you get instead?

Not Found (#404) Page not found. The above error occurred while the Web server was processing your request. Please contact us if you think this is a server error. Thank you.

Additional info

gig_books/common/config/main-local.php

<?php
    return [

'components' => [
    'db' => [
        'class' => 'yii\db\Connection',
        'dsn' => 'mysql:host=localhost;dbname=gigs',
        'username' => 'root',
        'password' => '',
        'charset' => 'utf8',
    ],

    'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'viewPath' => '@common/mail',

      'useFileTransport' => true,
    ],
    'urlManager' => [
        'enablePrettyUrl' => true,
        'rules' => [
            // your rules go here
        ],
    ],      
],

];

gig_books/backend/controllers/ApiController.php

    <?php

    namespace backend\controllers;

    use backend\models\Book;
    use yii;
    use yii\web\Controller;

    class ApiController extends Controller
    {
        public $enableCsrfValidation = false;  

    // =============================================================  Book  ==========================================================

public function actionMybook()
{
    \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
    $realbook = Book::find()->where('new_id = 3')->limit(1)->all();
    $data = array();
    if(count($realbook)>0)
    {
        foreach($realbook as $item)
        {
            $path = "http://$_SERVER[HTTP_HOST]" . Yii::$app->urlManager->baseUrl;
            $image = $path . '/images/books/' . $item->image;
            $image = str_replace(" ", "%20", $image);

            // full
            if(strlen($item->full)>0)
            {
                $fileFull = $path . 'uploads/full/' . $item->full;
                $fileFull = str_replace("web", "", $fileFull);
            }
            else
            {
                $fileFull = '';
            }

            $data[] = array(
                'id'=>$item->id,
                'new_id'=>$item->new_id,
                'title'=>$item->title,
                'author'=>$item->author,
                'price'=>$item->price,
                'description'=>$item->description,
                'image'=>$image,
                'full'=>$fileFull
            );
        }
        return array(
            'status' => 'SUCCESS',
            'data' => $data,
            'message' => 'OK',
        );
    }else
    {
        return array(
            'status' => 'ERROR',
            'message' => 'Not Found Data',
        );
    }
}

}

Error Logs

    Stack trace:
    #0 C:\wamp64\www\gig_books\vendor\yiisoft\yii2\web\Application.php(104): yii\base\Module->runAction('favicon.ico', Array)
    #1 C:\wamp64\www\gig_books\vendor\yiisoft\yii2\base\Application.php(392): yii\web\Application->handleRequest(Object(yii\web\Request))
    #2 C:\wamp64\www\gig_books\backend\web\index.php(21): yii\base\Application->run()
    #3 {main}

    Next yii\web\NotFoundHttpException: Page not found. in C:\wamp64\www\gig_books\vendor\yiisoft\yii2\web\Application.php:116
    Stack trace:
    #0 C:\wamp64\www\gig_books\vendor\yiisoft\yii2\base\Application.php(392): yii\web\Application->handleRequest(Object(yii\web\Request))
    #1 C:\wamp64\www\gig_books\backend\web\index.php(21): yii\base\Application->run()
    #2 {main}
    2022-08-03 05:18:03 [::1][-][f1ui3i3sc0og93bfudc5v798eq][info][application] $_GET = []

    $_POST = []

    $_FILES = []

    $_COOKIE = [
        '_ga' => 'GA1.1.1993777723.1588084931'
        'remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d' => 'eyJpdiI6Im5iMjY1OEtRcGpObU9PK0pCWjZmRWc9PSIsInZhbHVlIjoiSkxUR1BRK0lEbHA4ZXg4M05xMThJSVdFOCtkTEtNSmhrWkFZdUJxNElGaFBGK1BQeDFrcDZBUlZFY2ZYazQ2eTR4bStqTXVEVUZYMGJxRkRcLytpY0ZiaDVTXC94Z2NkT0lcL20yd0lXRHQ3V0R0N1VqT2tDWE9xdjN6ejNXMFRJajJhUWZWSmRxbFc5V0gxa3ErRGF0eVBMVHQwdHl3alNqWnF0MU1qcmFOa1pBPSIsIm1hYyI6IjRjNzMwZWI1YjgzYWNjN2Y3ZDUyZmJiZDhhMmY1MzczMTM2NzU4MGYyYThkOTVjOTU4NjdmMGU2MzQ1YzRiMWMifQ=='
        '__gads' => 'ID=d9f2c822bec381d3-22941f3d8ecc00a0:T=1635266564:RT=1635266564:S=ALNI_MZahoz9tA5NoNVoCwKNF4E1i8mGGA'
        'PHPSESSID' => 'f1ui3i3sc0og93bfudc5v798eq'
        '_csrf-backend' => 'f8e1cfcf4847f65ab773ce5ccc4194ebe817332677d6ac4f0cfc4f3b6539dd18a:2:{i:0;s:13:\"_csrf-backend\";i:1;s:32:\"5bWl0dvUU1k44WE0JlWYPGyQr1_fCgAu\";}'
    ]

    $_SESSION = [
        '__flash' => []
    ]

    $_SERVER = [
        'HTTP_HOST' => 'localhost'
        'HTTP_CONNECTION' => 'keep-alive'
        'HTTP_SEC_CH_UA' => '\".Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"103\", \"Chromium\";v=\"103\"'
        'HTTP_SEC_CH_UA_MOBILE' => '?0'
        'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
        'HTTP_SEC_CH_UA_PLATFORM' => '\"Windows\"'
        'HTTP_ACCEPT' => 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8'
        'HTTP_SEC_FETCH_SITE' => 'same-origin'
        'HTTP_SEC_FETCH_MODE' => 'no-cors'
        'HTTP_SEC_FETCH_DEST' => 'image'
        'HTTP_REFERER' => 'http://localhost/gig_books/backend/web/index.php/api'
        'HTTP_ACCEPT_ENCODING' => 'gzip, deflate, br'
        'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.9'
        'HTTP_COOKIE' => '_ga=GA1.1.1993777723.1588084931; remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d=eyJpdiI6Im5iMjY1OEtRcGpObU9PK0pCWjZmRWc9PSIsInZhbHVlIjoiSkxUR1BRK0lEbHA4ZXg4M05xMThJSVdFOCtkTEtNSmhrWkFZdUJxNElGaFBGK1BQeDFrcDZBUlZFY2ZYazQ2eTR4bStqTXVEVUZYMGJxRkRcLytpY0ZiaDVTXC94Z2NkT0lcL20yd0lXRHQ3V0R0N1VqT2tDWE9xdjN6ejNXMFRJajJhUWZWSmRxbFc5V0gxa3ErRGF0eVBMVHQwdHl3alNqWnF0MU1qcmFOa1pBPSIsIm1hYyI6IjRjNzMwZWI1YjgzYWNjN2Y3ZDUyZmJiZDhhMmY1MzczMTM2NzU4MGYyYThkOTVjOTU4NjdmMGU2MzQ1YzRiMWMifQ%3D%3D; __gads=ID=d9f2c822bec381d3-22941f3d8ecc00a0:T=1635266564:RT=1635266564:S=ALNI_MZahoz9tA5NoNVoCwKNF4E1i8mGGA; PHPSESSID=f1ui3i3sc0og93bfudc5v798eq; _csrf-backend=f8e1cfcf4847f65ab773ce5ccc4194ebe817332677d6ac4f0cfc4f3b6539dd18a%3A2%3A%7Bi%3A0%3Bs%3A13%3A%22_csrf-backend%22%3Bi%3A1%3Bs%3A32%3A%225bWl0dvUU1k44WE0JlWYPGyQr1_fCgAu%22%3B%7D'
        'PATH' => 'C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\ProgramData\\ComposerSetup\\bin;C:\\Program Files\\Git\\cmd;C:\\Program Files\\dotnet\\;C:\\Program Files\\nodejs\\;C:\\Gradle\\gradle-7.2\\bin;C:\\php7.4.26;C:\\ProgramData\\chocolatey\\bin;C:\\WINDOWS\\system32\\config\\systemprofile\\AppData\\Local\\Microsoft\\WindowsApps'
.....
    ]
Q A
Yii version 2.0.40
PHP version 7.4.26
Operating system Windows
bizley commented 2 years ago

Since you have not update the core, and we don't change anything in the previous versions, it's really difficult to say what happened here. I recommend posting this at the Yii forum, hopefully someone there can help you (and for example with some tips like using data providers and dedicated rest controller).

yii-bot commented 2 years ago

Thank you for your question. In order for this issue tracker to be effective, it should only contain bug reports and feature requests.

We advise you to use our community driven resources:

If you are confident that there is a bug in the framework, feel free to provide information on how to reproduce it. This issue will be closed for now.

This is an automated comment, triggered by adding the label question.

abayomiabayomi commented 2 years ago

Thank you @bizley