Symfony2 500错误但没有日志

时间:2014-04-13 17:43:24

标签: symfony logging controller show

我有一个" RealisationAwardsCategory"实体。当我想坚持这个对象时,一切都很完美。表单正常,视图显示正确,数据库保存工作。但是,当我想在show,edit或index视图中看到这个实体时,我有一个空白页面有500错误,但没有日志。我试图在apache errors.log和app / logs / prod.log中看到它(我在prod env中,但我试图在dev.log中看到它)。

这是我的实体:

<?php

namespace VisualImmersion\AdminBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * RealisationAwardsCategory
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="VisualImmersion\AdminBundle\Entity\Repository\RealisationAwardsCategoryRepository")
 */
class RealisationAwardsCategory
{
    /**
     * @var integer
     *
     * @ORM\Column(name="ID", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;


    /**
     * @ORM\ManyToMany(targetEntity="RealisationAwards", mappedBy="RealisationAwardsCategories")
     */
    private $awards;


    public function __construct()
    {
        $this->awards = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     * @return RealisationAwardsCategory
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Add Awards
     *
     * @param \VisualImmersion\AdminBundle\Entity\RealisationAwards $awards
     */
    public function addAwards(\VisualImmersion\AdminBundle\Entity\RealisationAwards $awards)
    {
        $this->awards[] = $awards;
    }

    /**
     * Get Awards
     *
     * @return \Doctrine\Common\Collections\ArrayCollection()
     */
    public function getAwards()
    {
        return $this->awards->toArray();
    }

    /**
     * Remove awards
     *
     * @param \VisualImmersion\AdminBundle\Entity\RealisationAwards $awards
     */
    public function removeAwards(\VisualImmersion\AdminBundle\Entity\RealisationAwards $awards)
    {
        $this->awards->removeElement($awards);
    }
}

我有这样的观点:

{% extends 'VisualImmersionAdminBundle::layout.html.twig' %}

{% block body -%}
    <h1>Realisation Awards Category</h1>

    <table class="record_properties">
        <tbody>
            <tr>
                <th>Name</th>
                <td>{{ entity.name }}</td>
            </tr>
        </tbody>
    </table>

        <ul class="record_actions">
    <li>
        <a href="{{ path('realisationawardscategory_index') }}">
            Back to the list
        </a>
    </li>
    <li>
        <a href="{{ path('realisationawardscategory_edit', { 'id': entity.id }) }}">
            Edit
        </a>
    </li>
            <li>
                <form action="{{ path('realisationawardscategory_delete', { 'id': entity.id }) }}" method="post">
                    <input type="hidden" name="_method" value="DELETE" />
                    {{ form_widget(delete_form) }}
                    <button type="submit">Delete</button>
                </form>
            </li>
</ul>
{% endblock %}

这是我的控制器显示动作:

 /**
     * Finds and displays a RealisationAwardsCategory entity.
     *
     * @Route("/{id}", name="realisationawardscategory_show")
     * @Method("GET")
     * @Template()
     */
    public function showAction($id)
    {
        $em = $this->getDoctrine()->getManager();

        $entity = $em->getRepository('VisualImmersionAdminBundle:RealisationAwardsCategory')->find($id);

        if (!$entity) {
            throw $this->createNotFoundException('Unable to find RealisationAwardsCategory entity.');
        }

        $deleteForm = $this->createDeleteForm($id);

        return array(
            'entity'      => $entity,
            'delete_form' => $deleteForm->createView(),
        );
    }

我的路线:

realisationawardscategory_index:
    path:  /realisationawardscategory
    defaults: { _controller: VisualImmersionAdminBundle:RealisationAwardsCategory:index }

realisationawardscategory_show:
    path:  /realisationawardscategory/{id}
    defaults: { _controller: VisualImmersionAdminBundle:RealisationAwardsCategory:show }
    requirements:
      id: \d+

realisationawardscategory_new:
    path:  /realisationawardscategory/new
    defaults: { _controller: VisualImmersionAdminBundle:RealisationAwardsCategory:new }

realisationawardscategory_create:
    path:  /realisationawardscategory/create
    defaults: { _controller: VisualImmersionAdminBundle:RealisationAwardsCategory:create }
    requirements:


realisationawardscategory_edit:
    path:  /realisationawardscategory/edit/{id}
    defaults: { _controller: VisualImmersionAdminBundle:RealisationAwardsCategory:edit }
    requirements:
      id: \d+

realisationawardscategory_update:
    path:  /realisationawardscategory/update/{id}
    defaults: { _controller: VisualImmersionAdminBundle:RealisationAwardsCategory:update }
    requirements:
      id: \d+

realisationawardscategory_delete:
    path:  /realisationawardscategory/delete/{id}
    defaults: { _controller: VisualImmersionAdminBundle:RealisationAwardsCategory:delete }
    requirements:
      id: \d+

我尝试使用monolog强制在我的日志中显示实体,如下所示:

$logger = $this->get('logger');
$logger->error('entity' . $entity);

但没有任何显示。

我希望首先知道节目中的错误是什么,以及为什么没有显示日志。

感谢您的帮助:)

1 个答案:

答案 0 :(得分:0)

您是否为控制器内的所有路径指定了公共前缀

/**
 * @Route("/realisationawardscategory")
 */
class <<your controller's name >> extends Controller {
 /**
     * Finds and displays a RealisationAwardsCategory entity.
     *
     * @Route("/{id}", name="realisationawardscategory_show")
     * @Method("GET")
     * @Template()
     */
    public function showAction($id)
    {
        << your code >>
    }
}// end of controller..