2013-10-20 47 views
0

我需要将我的应用程序与其数据库耦合。为此,我创建了一个实体doctrine:generate:entity。它生成了一个具有适当映射注释的实体。我还使用doctrine:schema:update --force在数据库服务器上实际创建了架构,我可以确认它已使用phpMyAdmin完成。保存Symfony实体时发生500服务器错误

在我的控制,我想简单地插入一行像这样:

public function testAction() { 
    $file = new File(); 
    $file->setTest('A Foo Bar'); 

    $em = $this->getDoctrine()->getManager(); 
    $em->persist($file); 
    $em->flush(); 

    return new JsonResponse(array('foo' => 'bar')); 
} 

只有一个场称为test实体是字符串,长度为255当我要求这个网址通过AJAX在我的应用程序的请求,它会引发背部非常不提供信息500内部服务器错误:

Oops! An Error Occurred

The server returned a "500 Internal Server Error".

Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.

的PHP错误日志也没有任何错误信息。如果我删除数据库操作的东西,此控制器操作确实有效。该应用程序也在开发环境中运行。

有什么办法可以得到一个更具描述性的错误信息,至少告诉我什么是错的?

+0

你通常会得到Symfony完全回溯错误吗?您是否创建了触发onPersist或任何其他Doctrine事件的EventListener? –

+0

清除缓存后再试一次! –

+0

你是否在生产环境中运行应用程序?如果是这样,你可以尝试设置登录(点击[这里](http://symfony.com/doc/current/cookbook/logging/monolog.html#using-several-handlers)查看[文档](http:/ /symfony.com/doc/current/cookbook/logging/monolog.html#using-several-handlers)) – acrobat

回答

0

这是您在生产中获得的默认错误页面。你可以自定义 - http://symfony.com/doc/current/cookbook/controller/error_pages.html

可以捕获并读取错误创建ExceptionListener - http://symfony.com/doc/current/cookbook/event_dispatcher/event_listener.html

您还可以切换到开发环境,以显示错误文本和日志。

如果你只是想开发日志,但prod环境,您可以复制monolog部分的内容app/config/config_dev.ymlapp/config/config_prod.yml

0

如果有人在这里遇到这个问题,并失去了原因在我的情况是我已经指定了一个新的@ORM \ ManyToOne关系,并坚持而不是合并实体。

这在过去已经返回了一个有效的错误,但在这种情况下,PHP脚本根本没有处理它。

+0

这不提供问题的答案。一旦你有足够的[声誉](https://stackoverflow.com/help/whats-reputation),你将可以[对任何帖子发表评论](https://stackoverflow.com/help/privileges/comment);相反,[提供不需要提问者澄清的答案](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- I-DO-代替)。 - [来自评论](/ review/low-quality-posts/18698586) –

相关问题