Sf4 - probléme affiche html

Par Issa, il y a 6 ans


Bonjour,

Voila je rencontre un petit problème avec mon code.

Ce que je fais

J'ai suivi le tuto de la video pour arriver au code ci-dessous

<?php namespace App\Controller; use Symfony\Component\HttpFoundation\Response; class HomeController { public function index(): Response { return new Response( content 'Salut les gens'); } }

Ce que je veux

d'aprés la video je devrais juste afficher à l'écran Salut les gens

Ce que j'obtiens

Du coup symfony m'affiche le message d'erreur ci-dessous

namespace App\Controller; use Symfony\Component\HttpFoundation\Response; class HomeController { public function index(): Response { return new Response( content 'Salut les gens'); } }

qu'en pensez vous svp

9 réponses

TheTakylo, il y a 6 ans

Ou a tu déclarer la route qui pointe vers ton controller ?

Issa, il y a 6 ans

Bonjour,

j'ai continué à chercehr et je galére :'(

premier probléme j'ai la debugBare qui ne s'affiche pas j'ai ça à la place :

An error occured while loading the web debug toolbar.

j'ai chercher sur le net il indique d'installer :
composer require symfony/apache-pack
Mais toujours pas de debugBar

mon deuxiéme probléme de routing.

dommage on peux pas poster des screenshoots.

voici mon controlleur :
'''
<?php
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class HomeController extends AbstractController{

/**

  • @Route ("/",name="home")
  • @return Response
    */
    public function index(): Response
    {
    return $this->render('pages/Home.html.twig');
    }

}
'''

voici mon PropertyController :
<?phparoundnamespace App\Controller;aroundarounduse Symfony\Bundle\FrameworkBundle\Controller\AbstractController;arounduse Symfony\Component\HttpFoundation\Response;arounduse Symfony\Component\Routing\Annotation\Route;aroundaroundaroundclass PropertyController extends AbstractController{aroundaround/**around * @Route("/biens",name="property.index")around * @return Responsearound */around public function index(): Responsearound {around return $this->render('property/index.html.twig');around }around}

Pas de soucis pour la page d'acceuil mais mon lien ne fonctionne pas :
ma racine de site est la suivante et fonctionne :
http://192.168.17.175/cours/MySuperAgence/public/
mais
le lien suivant :
http://192.168.17.175/cours/MySuperAgence/public/biens

devrait fonctionné grace à mon cotrolleur property.in,dex

mais je me retrouve avec une erreur 404 ?

comment c'est possible normalement synfony détect que ma route n'existe pas et me renvoi sur la debug bar.

lla il y a un truc qui m'échape

merci à vous

gallarian, il y a 6 ans

salut, pourrais-tu reposter ton code convenablement car vraiment dur a lire, de ce que j'ai pu voir y a pas d'erreur mais pas sur, donc reposte ton code, dans l'editeur tu peux poster du code avec le symbole a l'extreme droite "</>".

as tu pensé a vider ton cache en faisant un php bin/console c:c

et regarde aussi dans les routes dans la CLI en faisant un php bin/console debug:router pour voir si ta route y es.

Issa, il y a 6 ans

ok voici mon home controlleur :

<?php
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class HomeController extends AbstractController{

/**

  • @Route ("/",name="home")
  • @return Response
    */
    public function index(): Response
    {
    return $this->render('pages/Home.html.twig');
    }

}

et mon propertyControleur :

<?php
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class PropertyController extends AbstractController{

/**

  • @Route("/biens",name="property.index")
  • @return Response
    */
    public function index(): Response
    {
    return $this->render('property/index.html.twig');
    }
    }
gallarian, il y a 6 ans

ton code est correct, as tu essayé les commandes que je t'ai donné?

Issa, il y a 6 ans

oui j'ai vidé le cache : php bin/console cache:clear --no-warmup


Name Method Scheme Host Path


_twig_error_test ANY ANY ANY /_error/{code}.{_format}
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
home ANY ANY ANY <href=>/
property.index ANY ANY ANY <href=>/biens


j'ai vérifier que l'url rewrting est activé

c'est frustrant.

Pour donner plus de précision je suis sur un serveur web apache hebergé sur une ubuntun 18.04 LTS

gallarian, il y a 6 ans

bon ta route est bien reconnue: "property.index ANY ANY ANY /biens"

est ce que le projet en est mode dev ou prod? car si c'est en mode prod, tu dois faire php bin/console c:c --prod?

Issa, il y a 6 ans

Pourtant si j'ai la debug barre, c'est pour le dev ??

c'est vrais qu'avec l'ancien synfony pour allé sur le dev il fallait allé sur :

http://192.168.17.175/monApp/app_dev.php

alors que la je suis directement sur :
http://192.168.17.175/monApp/

mais bon j'ai activé les logs PHP

mais j'ai rien qui s'affiche sur la page de mon site.

Issa, il y a 6 ans

ok probléme résolu grace à ceci :

https://symfony.com/doc/current/setup/web_server_configuration.html

sudo nano /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>

The ServerName directive sets the request scheme, hostname and port that

    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
<Directory /var/www/html>
    AllowOverride All
    Order Allow,Deny
    Allow from All
</Directory>

# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
#     Options FollowSymlinks
# </Directory>

ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

vim: syntax=apache ts=4 sw=4 sts=4 sr noet

</VirtualHost>

sudo service apache2 restart

et la le rewrting fonctionne :)

merci