简体   繁体   中英

How can I add a new page on Symfony 4 without any 404 error?

I'm working on an imported project on Symfony 4.2 with Encore build system.

I installed all the module and everything is working fine.

But when I want to add a new page (requetes), I always get an 404 error.

Here is the project : https://github.com/LaboratoirePLH/ERC-MAP

  • PHP 7.2.11
  • PostgreSQL 9.6 with PostGIS 2.4
  • Symfony 4.2 with Encore build system
  • Bootstrap 4.2
  • jQuery 3
  • ChosenJS for jQuery (autocomplete combo box)
  • DataTables for jQuery (improved data tables)

I'm running PosteGre with Laragon.

I tried to ensure mod_rewrite on apache2.

I tried too to put an .httaccess file on the public/, still not working.

I checked the route with "php bin/console debug:route" and she is listed

https://i.imgur.com/p4naU6Z.png (I can't post the image I need more reputation)

The RequetesController.php :

/**
     * Page queries
     *
     * @Route("/requetes", name="requetes")
     */

     public function index(){

         return $this->render('requetes/index.html.twig');

     }

And the twig, in the requetes folder :

<html>
    <body>
        <h1>Hello {{ $requetes }}</h1>
    </body>
</html>

With the link " https://127.0.0.1:8000/requetes " I got a 404 error, and with " https://127.0.0.1:8000/ " it's working.

I'm a beginner on Symfony and I really need your help.

What you can try it's to call your twig like that :

return $this->render('requetes');

if it exists it have to display the page. If it exists can you show us the full error message ?

What is the content of your public/.htaccess file? Could you try with this one which come from the apache-pack recipe :

https://github.com/symfony/recipes-contrib/blob/master/symfony/apache-pack/1.0/public/.htaccess


EDIT :

Try to reformat your annotations ans action like this:

/**
 * Page queries
 *
 * @Route("/requetes", name="requetes")
 */
public function index()
{
    return $this->render('requetes/index.html.twig');
}

In your project directory create this file if it does not exist : project_dir/public/.htaccess and add the following content to the file

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /index.php/
    </IfModule>
</IfModule>

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