7

我是第一次使用 Silex。在本地开发时一切正常。将所有内容上传到生产服务器后,参数化路线将不再起作用。

你有什么主意吗?
我是否在某处缺少生产配置?
我在某处缺少文件权限吗?

我得到了这两个例外:

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

和:

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

这是代码:

<?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();

开发服务器是 PHP 5.4 内置 webserver 生产服务器是 PHP 5.3 CentOS

.htaccess 文件基本相同。在生产环境中,silex 应用程序位于文档根目录的子文件夹中,比如说 /prevendita,所以我添加了

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

将任何以 /prevendita 开头的请求重定向到我的 silex 应用程序

4

2 回答 2

9

你写了:

/prevendita/hello/{name}/

但要求:

/prevendita/hello/sadfasdf

你忘记了尾部的斜线。
我认为这就是问题所在。

编辑:根据 Fabien Potencier(Silex 的作者):

  • 每个资源都必须有一个唯一的 URL(因此/foo/不同于/foo)。
  • 为了方便最终用户(而不是开发人员),当 URL 必须以 a 结尾/并且如果他忘记键入它时,Silex 会将他重定向到正确的 URL(带有 a /)而不是返回 a 404
  • 当 Silex 生成 URL 时,它们总是使用规范 URL,因此仅当用户手动输入 URL 并忘记添加结尾时才会进行重定向/,但框架本身从不使用它。
于 2012-07-24T15:59:53.607 回答
2

最好的选择是将您的域指向/prevendita/web/而不使用重写引擎来处理子目录。我想你在域下还有一些其他的东西,所以也许你不能将它指向你的 Silex 应用程序,但是你可以使用子域而不是请求yourdomain.com/prevendita/web/index.php你可以请求prevendita.yourdomain.com/index.php(域指向web)。

于 2014-10-25T02:03:52.063 回答