Riz*_*iza 12 symfony-routing symfony4
好的,所以我刚刚安装了最新版本的Symfony 4.安装完成后运行浏览器并显示一个不错的欢迎问候语.都好!
然后我使用创建了一个新的控制器make:controller.我将此控制器命名为Client,并使用Annotations,与其他默认控制器相同.我按如下方式配置了路由:
/**
* @Route("/client", name="client")
*/
public function index()
{
// replace this line with your own code!
return $this->render('@Maker/demoPage.html.twig', [ 'path' => str_replace($this->getParameter('kernel.project_dir').'/', '', __FILE__) ]);
}
Run Code Online (Sandbox Code Playgroud)
我刷新浏览器,一切都很好,没有错误.
然后我手动在浏览器中键入路径以检查它是否真的有效:
localhost:8000/client
Run Code Online (Sandbox Code Playgroud)
问题.该网址返回标准apache 404
Not Found
The requested URL /client was not found on this server.
Apache/2.4.18 (Ubuntu) Server at new.staff-fdr.dev Port 80
Run Code Online (Sandbox Code Playgroud)
调试路径看到了这一点:
-------------------------- -------- -------- ------ ------------------
Name Method Scheme Host Path
-------------------------- -------- -------- ------ -----------------
client ANY ANY ANY /client
index ANY ANY ANY /
_twig_error_test ANY ANY ANY /_error/{code}.
Run Code Online (Sandbox Code Playgroud)
mal*_*olm 27
缺少.htaccess文件.
composer config extra.symfony.allow-contrib true
composer req symfony/apache-pack
Run Code Online (Sandbox Code Playgroud)
我也有这个问题,如果这对你不起作用,这里有一些其他的想法。一种是按照此处的说明配置您的 Web 服务器。带有 mod_php 的优化 apache 对我有用:
https://symfony.com/doc/master/setup/web_server_configuration.html
其次,我的网络服务器上没有启用 mod 重写。这最终是让我振作起来的解决方法。跑:
须藤 a2enmod 重写
然后
须藤服务 apache2 重启
那应该能让你继续前进。
| 归档时间: |
|
| 查看次数: |
7193 次 |
| 最近记录: |