简体   繁体   English

Symfony 4.0无法正常工作

[英]Symfony 4.0 doesn't work

To the point: 要点:
- I created new project on symfony 4.0: composer create-project symfony/skeleton sf4 -我在symfony 4.0上创建了新项目: composer create-project symfony/skeleton sf4
- Welcome page is working -欢迎页面正在运行
- I wanted to create my first page with https://symfony.com/doc/current/page_creation.html and I did exactly what they say: create controller and route -我想使用https://symfony.com/doc/current/page_creation.html创建我的第一页,我完全按照他们说的做:创建控制器和路由
- Welcome page changed status to: No route found for "GET /" <-Solved -欢迎页面状态更改为:未No route found for "GET /" <-已解决
- new page path can't find file - Error 404 -新页面路径找不到文件-错误404

What am I doing wrong? 我究竟做错了什么? That is silly 真傻

~src/Controller/SecurityController.php 〜src / Controller / SecurityController.php

<?php
namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;

class SecurityController {
    public function logowanie() {
        return new Response(
            '<html><body>Logowanie</body></html>'
        );
    }
}


~config/routes.yaml 〜config / routes.yaml

index:
    path: /
    controller: App\Controller\MainController::index

logowanie:
    path: /logowanie
    controller: App\Controller\SecurityController::logowanie

EDIT: 编辑:
Home page works - thanks @Cerad 主页的作品-感谢@Cerad

I had the same problem. 我有同样的问题。 Homepage was working, but any other urls generate a 404, served by apache, and not logged in symfony. 主页正在运行,但是其他任何URL都会生成404,由apache提供,并且未登录symfony。

My mistake was the missconfiguration of the virtualhost. 我的错误是虚拟主机的配置错误。 As there is no longer .htaccess in the public directory, you have to configure redirection & rewrite in your virtualhost. 由于公共目录中不再存在.htaccess,因此您必须在虚拟主机中配置重定向和重写。 Here is the documentation: https://symfony.com/doc/master/setup/web_server_configuration.html 以下是文档: https : //symfony.com/doc/master/setup/web_server_configuration.html

在此处输入图片说明

There's no real route nor controller with welcome template on Symfony 4 apps, it's just a trick to improve the user's first experience. Symfony 4应用程序上没有真正的路线或带有欢迎模板的控制器,这只是改善用户的首次体验的一种技巧。

The welcome response work only for root path / and upon added a route or installed a bundle that adds one (eg TwigBundle) this response disappears, as well as if debug mode has been deactivated. 欢迎响应仅适用于根路径/并且在添加路由或安装捆绑添加一个路由后(例如TwigBundle),该响应会消失,并且调试模式已停用。

Even, the status code of this response still is 404 (NOT FOUND). 甚至,此响应的状态代码仍为404(未找到)。

This code is the solution in Symfony 4.1: 这段代码是Symfony 4.1中的解决方案:

composer require symfony/apache-pack

After the link can be used: 链接可用后:

http://localhost/(name-project)/public/index.php/(name of controller)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM