2012-07-24 15 views
5

Estoy usando Silex por primera vez. Todo funciona bien mientras se desarrolla localmente. Una vez cargado todo en el servidor de producción, las rutas parametrizadas ya no funcionan.Enrutamiento Silex no encontrado

¿Alguna idea?
¿Me faltan configuraciones de producción en alguna parte?
¿Me faltan permisos de archivos en alguna parte?

que estoy recibiendo estas dos excepciones:

NotFoundHttpException: No route found for "GET /prevendita/hello/sadfasdf" 
in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/EventListener/RouterListener.php line 92 
    at RouterListener->onKernelRequest(object(GetResponseEvent)) 
    at call_user_func(array(object(RouterListener), 'onKernelRequest'), object(GetResponseEvent)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php line 164 
    at EventDispatcher->doDispatch(array(array(object(Application), 'onEarlyKernelRequest'), array(object(SessionServiceProvider), 'onEarlyKernelRequest'), array(object(RouterListener), 'onKernelRequest'), array(object(LocaleListener), 'onKernelRequest'), array(object(Application), 'onKernelRequest')), 'kernel.request', object(GetResponseEvent)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php line 53 
    at EventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php line 110 
    at HttpKernel->handleRaw(object(Request), '1') in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php line 73 
    at HttpKernel->handle(object(Request), '1', true) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/silex/silex/src/Silex/Application.php line 509 
    at Application->handle(object(Request)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/silex/silex/src/Silex/Application.php line 484 
    at Application->run() in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/web/index.php line 49 

Y:

ResourceNotFoundException: 
in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/routing/Symfony/Component/Routing/Matcher/UrlMatcher.php line 81 
    at UrlMatcher->match('/prevendita/hello/sadfasdf') in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/routing/Symfony/Component/Routing/Matcher/RedirectableUrlMatcher.php line 30 
    at RedirectableUrlMatcher->match('/prevendita/hello/sadfasdf') in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/silex/silex/src/Silex/LazyUrlMatcher.php line 51 
    at LazyUrlMatcher->match('/prevendita/hello/sadfasdf') in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/EventListener/RouterListener.php line 78 
    at RouterListener->onKernelRequest(object(GetResponseEvent)) 
    at call_user_func(array(object(RouterListener), 'onKernelRequest'), object(GetResponseEvent)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php line 164 
    at EventDispatcher->doDispatch(array(array(object(Application), 'onEarlyKernelRequest'), array(object(SessionServiceProvider), 'onEarlyKernelRequest'), array(object(RouterListener), 'onKernelRequest'), array(object(LocaleListener), 'onKernelRequest'), array(object(Application), 'onKernelRequest')), 'kernel.request', object(GetResponseEvent)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php line 53 
    at EventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php line 110 
    at HttpKernel->handleRaw(object(Request), '1') in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php line 73 
    at HttpKernel->handle(object(Request), '1', true) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/silex/silex/src/Silex/Application.php line 509 
    at Application->handle(object(Request)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/silex/silex/src/Silex/Application.php line 484 
    at Application->run() in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/web/index.php line 49 

Este es el código:

<?php 
require_once __DIR__.'/../vendor/autoload.php'; 

use Teatro\Models\Reservation; 
use Teatro\Models\ReservationsSeat; 
use Symfony\Component\Validator\Constraints; 
use Symfony\Component\Form\FormError; 

$app = new Silex\Application(); 
$app['debug'] = true; 

$app->register(new Silex\Provider\TwigServiceProvider(), array(
    'twig.path' => __DIR__.'/../views', 
)); 
$app->register(
    new Silex\Provider\UrlGeneratorServiceProvider() 
); 
$app->register(
    new Silex\Provider\SessionServiceProvider(), array(
//  'session.storage.options' => array('name' => 'test') 
    ) 
); 
$app->register(
    new Silex\Provider\FormServiceProvider() 
); 
$app->register(
    new Silex\Provider\ValidatorServiceProvider() 
); 
$app->register(new Silex\Provider\TranslationServiceProvider(), array(
    'translator.messages' => array(), 
)); 
$app->register(
    new Silex\Provider\SwiftmailerServiceProvider() 
); 

$app->get('/prevendita/hello/{name}/', function ($name) use ($app) { 
    return "Hello $name!"; 
})->bind('hello_name'); 

$app->get('/prevendita/hello', function() use ($app) { 
    return "Hello!"; 
})->bind('hello'); 

$app->run(); 

servidor de desarrollo es PHP 5.4 servidor web incorporado del servidor Producción es PHP 5.3 CentOS

. Los archivos de acceso son básicamente los mismos. En el env producción, la aplicación de sílex es en una subcarpeta de la raíz del documento digamos/Prevendita así que añadió

RewriteRule ^prevendita /prevendita/web/index.php [L] 

para redirigir cualquier solicitud comenzando con/Prevendita a mi aplicación silex

+0

¿Puedes pegar las stacktraces? – Florent

+0

Según la segunda excepción, ninguna ruta coincide. ¿Tal vez puedas pegar tus rutas? – Florent

+0

problema es localmente el mismo archivo funciona perfectamente.Además de esto, funciona perfectamente en producción si la ruta es estática. Si agrego un parámetro en la ruta, dice ruta no encontrada. – user1170896

Respuesta

8

Usted escribió:

/prevendita/hello/{name}/ 

pero pidió:

/prevendita/hello/sadfasdf 

Olvidó la barra final.
Creo que ese es el problema.

Editar: Según Fabien Potencier (autor de Silex):

  • Cada recurso debe tener un URL único (hasta /foo/ es diferente de /foo).
  • Como una conveniencia para el usuario final (no el desarrollador), cuando una URL debe terminar con / y si olvida escribirla, Silex lo redirecciona a la URL correcta (con /) en lugar de devolver 404.
  • Cuando Silex genera URL, siempre usa la URL canónica, por lo que la redirección solo se realiza cuando un usuario ingresa una URL manualmente y olvida agregar la / posterior, pero nunca la utiliza el propio marco.
+1

lamentablemente este no es el caso. Hay un error sobre la barra al final, pero ninguno de los dos funciona con o sin la barra al final. – user1170896

+1

@Florent, ¿es posible hacer que la barra diagonal final sea opcional, de modo que solo necesito especificar una ruta en lugar de dos haciendo el mismo proceso, donde una ruta contiene la barra diagonal y la otra no? – forestclown

1

La mejor opción es apuntar su dominio a /prevendita/web/ y no utilizar el motor de reescritura para manejar el subdirectorio. Supongo que tiene otras cosas bajo dominio, así que tal vez no pueda apuntarlo a su aplicación Silex, pero puede usar el subdominio y en lugar de solicitar yourdomain.com/prevendita/web/index.php puede solicitar prevendita.yourdomain.com/index.php (con el dominio apuntando al web).