this is my first post so i'll try to be understandable.
I am starting with symfony, and there is a problem i can't resolve alone.
This is my controller, and I am working with WAMP. When my Url is "mysite.local", it work normally, and it show me what it should (thanks to the home() function). But when my Url is "mysite.local/hello", i have the following error.
Not Found
The requested URL was not found on this server.
Apache/2.4.41 (Win64) PHP/7.4.0 Server at mysite.local Port 80
I guess this is normal as i didn't created any file named "hello", but it's working in the formation i am following.
Could you help me please ? Thank you
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class HomeController extends AbstractController
{
/**
* @Route("/hello", name="hello")
*/
public function hello()
{
return new Response("Bonjour ...");
}
/**
*@Route("/", name="homepage");
*/
public function home(){
$prenoms = ["Lior" => 17 , "Joseph" => 12, "Anne" => 55];
return $this->render("home.html.twig",
[
'title' => "Bonjour a tous :)",
'age' => "31 ",
'tableau' => $prenoms,
]);
}
}
?>
3条答案
按热度按时间ds97pgxw1#
请尝试使用
mysite.local/index.php/hello
如果可以,那就意味着.htaccess文件丢失或者mod_rewrite没有在apache服务器上启用。
首先你可以跑
自动添加.htaccess并进行测试,如果路由工作正常,则一切正常。
否则,您必须编辑
httpd.conf
或apache2.conf
文件并启用mod_rewrite
0pizxfdo2#
服务器上缺少apache,无法添加.htaccess文件
chhkpiq43#
需要用
composer
上面的方式创建.htaccess
文件,但是symfony/apache-pack
默认情况下不会执行,需要把y
或者通过复制
public
文件夹内的以下内容手动创建.htaccess
文件,index.php
文件位于该文件夹中,则所有路由都将工作。