简体   繁体   中英

404 not found when navigate by route on symfony

When i navigate on route i can't see my page web, i has just get 404 not found

# config/routes/attributes.yaml 
controllers: 
  resource: ../../src/Controller/ 
  type: attribute 
kernel: 
  resource: ../../src/Kernel.php 
  type: attribute``` 

# Controller 

namespace App\Controller; 
use Symfony\Component\HttpFoundation\Response; 
class LuckyController { 
  #[Route('/lucky/number')] 
  public function number(): Response { 
    $number = random_int(0, 100); 
    return $this->render('lucky/number.html.twig', [ 'number' => $number, ]); } }

# Twig (not relevant to question)

{# templates/lucky/number.html.twig #} 
<h1>Your lucky number is {{ number }}</h1>

I think you are need .htaccess for rewrite url, install apache-patch, and it will take care of the config and adding htaccess.

Install apache pack

composer require symfony/apache-pack

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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