Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
587 views
in Technique[技术] by (71.8m points)

symfony4 - Route is in debug list but returns 404 in Symfony 4

Ok, so I just installed latest version Symfony 4. Run the browser after installation and a nice welcome greeting shows. All good!

Then I created a new controller using make:controller. I named this controller Client and is using Annotations, same with the other Default Controller. I configured the routing as follows:

/**
 * @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__) ]);
}

I refreshed the browser and all good, no errors.

Then I manually typed the path into the browser to check if it's really working:

localhost:8000/client

Problem. The url returned standard 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

The debug route sees this though:

-------------------------- -------- -------- ------ ------------------
  Name                       Method   Scheme   Host   Path   

 -------------------------- -------- -------- ------ -----------------
  client                     ANY      ANY      ANY    /client  
  index                      ANY      ANY      ANY    /       
  _twig_error_test           ANY      ANY      ANY    /_error/{code}.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Missing .htaccess file.

composer config extra.symfony.allow-contrib true

composer req symfony/apache-pack

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...