在symfony中找不到404

Dan*_*ada 9 php symfony

我需要一个测试功能,但它不起作用.据说路由+控制器应该工作,但我找不到404.

这是我的/app/config/routing.yml:

AndroidAPIBundle:
    resource: "@MDPIAndroidApiBundle/Controller/"
    type:     annotation
    prefix:   /
Run Code Online (Sandbox Code Playgroud)

Controller我有内部目录LoginController.php:

/**
 * @Route("/api/test", name="test")
 */
public function getAction(Request $request)
{
    $format = "json";
    $view = View::create()->setStatusCode(201)->setData(array("status"=>"OK", "data"=>array("test" => "DAN TEST")))->setFormat($format);
    return $this->get('fos_rest.view_handler')->handle($view);
}
Run Code Online (Sandbox Code Playgroud)

那么为什么当我发出卷曲请求时,我收到了404消息?也在浏览器中添加/api/test到我的本地URL.

编辑

php app/console router:debug

test                                         ANY    ANY    ANY  /api/test
Run Code Online (Sandbox Code Playgroud)

编辑2

/etc/nginx/sites-available/susy_android_final

server {
    listen                  80;
    server_name             susy.android.final.local;
    access_log              /var/log/nginx/susy_android_final.access.log;
    error_log               /var/log/nginx/susy_android_final.error.log;
    root                    /var/www/susy.mdpi.com.final/web;

    client_max_body_size 500M;
    large_client_header_buffers 8 64k; 

    location / {
            index app_dev.php;
            if (-f $request_filename) {
            break;
            }
            rewrite ^(.*)$ /app_dev.php last;
    }
    ## Parse all .php file in the /var/www directory
   location ~ (app|app_dev|app_eudev).php {
            fastcgi_split_path_info         ^(.+\.php)(.*)$;                
            fastcgi_pass                    unix:/var/run/php/php5.6-fpm.sock; 
            #fastcgi_pass                   127.0.0.1:9001; 
            #fastcgi_index                  index.php;
            fastcgi_param                   SCRIPT_FILENAME  $request_filename;
            include                         fastcgi_params;

   }


}
Run Code Online (Sandbox Code Playgroud)

/etc/hosts

127.0.0.1 susy.android.final.local
Run Code Online (Sandbox Code Playgroud)

这是在ubuntu中

小智 0

我认为您已经正确配置了 symfony,但是您的浏览器和 symfony 之间的某些内容已损坏。我建议为您的配置编写功能测试

https://symfony.com/doc/2.8/testing.html

namespace AppBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class LoginControllerTest extends WebTestCase
{
    public function testGetAction()
    {
        $client = static::createClient();
        $client->request('GET', '/api/test');
        $this->assertTrue($client->getResponse()->isSuccessful());
    }
}
Run Code Online (Sandbox Code Playgroud)

如果您的测试工作正常,那么您的配置一切正常。然后你应该看看你是否登陆了正确的网络服务器并为symfony配置网络服务器(通常根目录应该位于网络文件夹中)