2016-06-22 26 views
5

Sono nuovo a Symfony ma non a PHP. Non riesco proprio a capire perché non riesco a ottenere una rotta della home page per funzionare da un pacchetto personalizzato, ma sembra che funzioni dall'output della console. Quando eseguo il percorso nel mio browser Web, verrà sempre retunrata la route / dall'AppBundle, ovvero la pagina di benvenuto predefinita di Symfony anche se l'AppBundle è stato rimosso dalla funzione registerBundles() in AppKernal.php. Posso confermare questo perché se cancellare la directory AppBundle da/src mi metterò il seguente log degli errori:Il routing di Symfony tramite bundle personalizzato funziona solo in modalità console

[2016-06-22 19:07:57] request.INFO: Matched route "homepage". {"route_parameters":{"_controller":"AppBundle\\Controller\\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://bvd-v3.dev/"} [] 
[2016-06-22 19:07:57] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] 
[2016-06-22 19:07:57] request.CRITICAL: Uncaught PHP Exception InvalidArgumentException: "Class "AppBundle\Controller\DefaultController" does not exist." at /Users/apple/projects/mentel/bvd-v3/var/cache/prod/classes.php line 2498 {"exception":"[object] (InvalidArgumentException(code: 0): Class \"AppBundle\\Controller\\DefaultController\" does not exist. at /Users/apple/projects/mentel/bvd-v3/var/cache/prod/classes.php:2498)"} [] 

Eppure, se chiamo php bin/console router:match /

L'output è:

+--------------+---------------------------------------------------------+ 
| Property  | Value             | 
+--------------+---------------------------------------------------------+ 
| Route Name | homepage            | 
| Path   |/              | 
| Path Regex | #^/$#s             | 
| Host   | ANY              | 
| Host Regex |               | 
| Scheme  | ANY              | 
| Method  | ANY              | 
| Requirements | NO CUSTOM            | 
| Class  | Symfony\Component\Routing\Route       | 
| Defaults  | _controller: MentelBundle:Index:index     | 
| Options  | compiler_class: Symfony\Component\Routing\RouteCompiler | 
+--------------+---------------------------------------------------------+ 

Se chiamo php bin/console debug:router

L'output è:

-------------------------- -------- -------- ------ ----------------------------------- 
    Name      Method Scheme Host Path        
-------------------------- -------- -------- ------ ----------------------------------- 
    _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_info    ANY  ANY  ANY /_profiler/info/{about}    
    _profiler_phpinfo   ANY  ANY  ANY /_profiler/phpinfo     
    _profiler_search_results ANY  ANY  ANY /_profiler/{token}/search/results 
    _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 
    _twig_error_test   ANY  ANY  ANY /_error/{code}.{_format}   
    homepage     ANY  ANY  ANY /         

Contenuto del routing.yml:

mentel: 
    resource: "@MentelBundle/Controller/" 
    type:  annotation 

Contenuti di routing_dev.yml:

_wdt: 
    resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml" 
    prefix: /_wdt 

_profiler: 
    resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml" 
    prefix: /_profiler 

_errors: 
    resource: "@TwigBundle/Resources/config/routing/errors.xml" 
    prefix: /_error 

_main: 
    resource: routing.yml 

Contenuti di registerBundles() in /app/AppKernal.php:

public function registerBundles() 
{ 
    $bundles = [ 
     new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), 
     new Symfony\Bundle\SecurityBundle\SecurityBundle(), 
     new Symfony\Bundle\TwigBundle\TwigBundle(), 
     new Symfony\Bundle\MonologBundle\MonologBundle(), 
     new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), 
     new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), 
     new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), 
     new BVD\MentelBundle\MentelBundle(), 
    ]; 

    if (in_array($this->getEnvironment(), ['dev', 'test'], true)) { 
     $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); 
     $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); 
     $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); 
     $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); 
    } 

    return $bundles; 
} 

Contenuto del controller:

<?php 

namespace BVD\MentelBundle\Controller; 

use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 

class IndexController extends Controller 
{ 
    /** 
    * @Route("/", name="homepage") 
    */ 
    public function indexAction() 
    { 
     die('?'); 
     return $this->render('@mentel/pages/home.html.twig', array(
      // ... 
     )); 
    } 

} 

Grazie per aver letto la mia domanda, apprezzerei davvero qualsiasi aiuto tu possa offrire.

+0

quindi penso che ci sia e incompreso. @Route ("/", name = "homepage") significa hostname.de/ ist il percorso se vuoi hostname.de/ homepage @Route ("/ homepage", name = "homepage") dovresti usare – fucethebads

+0

I don ' Voglio che '/ homepage' Voglio una rotta servita dal dominio, cioè' http: // example.com' che sarebbe un '/' ma quello che dici non ha importanza, perché cambia il percorso in '/ something_else 'darebbe solo un Symfony 404. Poiché non esiste una route AppBundle per questo. – DrewT

+2

Hai provato a svuotare la cache ('bin/console cache: clear')? – Oldskool

risposta

0

Run:

php bin/console cache:clear --env=prod 
Problemi correlati