我的symfony2页面在刷新后进入无限循环

时间:2013-05-03 16:12:58

标签: symfony doctrine-orm mapping entity-relationship relationship

当我进入显示群组细节的页面时,我遇到了非常奇怪的行为 当我第一次启动服务器时加载页面时,页面会按预期显示内容。但是,如果我按下刷新,浏览器将进入无限循环,服务器永远不会响应(在chrome和safari上测试)。

任何帮助都会受到赞赏

一些可以帮助找到错误的元素

  • 显然,从下面的日志中,应用程序无法从会话中读取SecurityContext

  • 网站上的所有其他页面效果都很好。

  • 这是我第一次做一个具有教义属性的关联,我必须在这里做错了。

  • 在我的关联实体中,我试图用返回associationId的getId替换返回goupeID的getId()(在下面的代码中注释) - >同样的结果。

  • 当我重新加载页面时,我得不到服务器(Mamp)的响应,我必须重新启动服务器才能使应用程序再次运行。

  • 我的捆绑包的真实姓名已重命名以保护隐私(因此该名称上的拼写错误并不重要

GroupeController (摘录)

/**
 * Finds and displays a Groupe entity.
 *
 * @Route("groupe/{id}", name="groupe_show")
 * @Method("GET")
 * @Template()
 */
public function showAction($id) {

    $em = $this->getDoctrine()->getManager();

    $groupe = $em->getRepository('myBundle:AssociationUserGroupe')->findOneBy(array('groupe'=>$id));

    if (!$groupe) {
        throw $this->createNotFoundException("not found");
    }

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

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

AssociationUserGroupe实体

<?php

namespace \myBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * AssociationUserGroupe
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class AssociationUserGroupe
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;


    /**
     * @var Groupe
     * @ORM\ManyToOne(targetEntity="Groupe", inversedBy="members")
     */
    private $groupe;

    /**
     * @var User
     * @ORM\ManyToOne(targetEntity="User", inversedBy="groupes")
     */
    private $user;

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

    /**
     * @var boolean
     *
     * @ORM\Column(name="confirmed", type="boolean")
     */
    private $confirmed;

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


    /**
     * Return The groupId instead
     *
     * @return integer 
     */
//    public function getId()
//    {
//        return $this->id;
//    }

    /**
     * Set identity
     *
     * @param string $identity
     * @return AssociationUserGroupe
     */
    public function setIdentity($identity)
    {
        $this->identity = $identity;

        return $this;
    }

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

    /**
     * Set confirmed
     *
     * @param boolean $confirmed
     * @return AssociationUserGroupe
     */
    public function setConfirmed($confirmed)
    {
        $this->confirmed = $confirmed;

        return $this;
    }

    /**
     * Get confirmed
     *
     * @return boolean 
     */
    public function getConfirmed()
    {
        return $this->confirmed;
    }

    /**
     * Set role
     *
     * @param string $role
     * @return AssociationUserGroupe
     */
    public function setRole($role)
    {
        $this->role = $role;

        return $this;
    }

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

    /**
     * Set groupe
     *
     * @param \myBundle\Entity\Groupe $groupe
     * @return AssociationUserGroupe
     */
    public function setGroupe(\myBundle\Entity\Groupe $groupe = null)
    {
        $this->groupe = $groupe;

        return $this;
    }

    /**
     * Get groupe
     *
     * @return \myBundle\Entity\Groupe 
     */
    public function getGroupe()
    {
        return $this->groupe;
    }

    /**
     * Set user
     *
     * @param \myBundle\Entity\User $user
     * @return AssociationUserGroupe
     */
    public function setUser(\myBundle\Entity\User $user = null)
    {
        $this->user = $user;

        return $this;
    }

    /**
     * Get user
     *
     * @return \myBundle\Entity\User 
     */
    public function getUser()
    {
        return $this->user;
    }




    //GROUPE SIDE GETTER

    /**
     * Get The name of the groupe
     * @return String
     */
    public function getName(){
        return $this->groupe->getName();
    }

    /**
     * Get The description of the groupe
     * @return String
     */
    public function getDescription(){
        return $this->groupe->getDescription();
    }

    /**
     * Get The description of the groupe
     * @return String
     */
    public function getId(){
        return $this->groupe->getId();
    }


    /**
     * Get The description of the groupe
     * @return String
     */
    public function getOwner(){
        return $this->groupe->getOwner();
    }


}

用户实体

<?php

namespace myBundle\Entity;

use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity
 * @ORM\Table(name="myUser")
 */
class User extends BaseUser {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\OneToMany(targetEntity="AssociationUserGroupe", mappedBy="user")
     */
    private $groupes;

    public function __construct() {
        parent::__construct();
        $this->groupes = new ArrayCollection();
    }

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

    /**
     * Add groupes
     *
     * @param \myBundle\Entity\AssociationUserGroupe $groupes
     * @return User
     */
    public function addGroupe(\myBundle\Entity\AssociationUserGroupe $groupes)
    {
        $this->groupes[] = $groupes;

        return $this;
    }

    /**
     * Remove groupes
     *
     * @param \myBundle\Entity\AssociationUserGroupe $groupes
     */
    public function removeGroupe(\myBundle\Entity\AssociationUserGroupe $groupes)
    {
        $this->groupes->removeElement($groupes);
    }

    /**
     * Get groupes
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getGroupes() {
        return $this->groupes;
    }

    /**
     * Get groupes differ from getGroupes because it return only the group entity and not the AssociationUserGroupe
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getGroupesOnly() {
        $groupes = new ArrayCollection();
        foreach ($this->groupes as $groupe) {
            $groupes[] = $groupe->getGroupe();
        }
        return $groupes;
    }


    public function hasAccessTo(\myBundle\Entity\Groupe $groupe){
        return $this->getGroupesOnly()->contains($groupe);
    }
    public function hasAccessToEdit(\myBundle\Entity\Groupe $groupe){
        return $this->getGroupesOnly()->contains($groupe);
    }

    /**
     * return true if this user has a group
     * @return Boolean
     */
    public function hasGroupe(){
        return !$this->getGroupes()->isEmpty();
    }


}

会员实体

<?php

namespace myBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
 * Groupe
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class Groupe
{
    /**
     * @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;

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

    /**
     * @var Members
     * @ORM\OneToMany(targetEntity="AssociationUserGroupe", mappedBy="groupe")
     */
    private $members;

    public function __construct() {
        $this->users = new ArrayCollection();
    }

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

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

        return $this;
    }

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

    /**
     * Set description
     *
     * @param string $description
     * @return Groupe
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

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

    /**
     * Set owner
     *
     * @param \myBundle\Entity\User $owner
     * @return Groupe
     */
    public function setOwner(\myBundle\Entity\User $owner = null)
    {
        $this->owner = $owner;

        return $this;
    }

    /**
     * Get owner
     *
     * @return \myBundle\Entity\User 
     */
    public function getOwner()
    {
        return $this->getMembersBy(array('role'=>'owner'));
    }

    /**
     * Add members
     *
     * @param \myBundle\Entity\User $members
     * @return Groupe
     */
    public function addMember(\myBundle\Entity\User $members)
    {
        $this->members[] = $members;

        return $this;
    }

    /**
     * Remove members
     *
     * @param \myBundle\Entity\User $members
     */
    public function removeMember(\myBundle\Entity\User $members)
    {
        $this->members->removeElement($members);
    }

    /**
     * Get members
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getMembers()
    {
        return $this->members;
    }

    /**
     * Get members
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getMembersBy($options)
    {
        foreach ($this->members as $member) {
            die($member);
        }
        return $this->members;
    }

}

和视图

{% extends '::base.html.twig' %}

{% block body -%}
    <h1>Groupe</h1>

    <table class="record_properties">
        <tbody>
            <tr>
                <th>Id</th>
                <td>{{ groupe.id }}</td>
            </tr>
            <tr>
                <th>Name</th>
                <td>{{ groupe.name }}</td>
            </tr>
            <tr>
                <th>Description</th>
                <td>{{ groupe.description }}</td>
            </tr>
        </tbody>
    </table>

        <ul class="record_actions">
    <li>
        <a href="{{ path('groupe') }}">
            Back to the list
        </a>
    </li>
    {% if (groupe.owner == app.user) %}
    <li>
        <a href="{{ path('groupe_invit', { 'id': groupe.id }) }}">
            Inviter un User
        </a>
    </li>
    {% endif %}
    <li>
        <a href="{{ path('groupe_edit', { 'id': groupe.id }) }}">
            Edit
        </a>
    </li>
    <li>
        <form action="{{ path('groupe_delete', { 'id': groupe.id }) }}" method="post">
            <input type="hidden" name="_method" value="DELETE" />
            {{ form_widget(delete_form) }}
            <button type="submit">Delete</button>
        </form>
    </li>
</ul>
{% endblock %}

记录(首次显示)

==> app/logs/dev.log <==
[2013-05-03 18:15:48] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". [] []
[2013-05-03 18:15:48] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". [] []
[2013-05-03 18:15:48] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". [] []
[2013-05-03 18:15:48] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". [] []
[2013-05-03 18:15:48] request.INFO: Matched route "groupe_show" (parameters: "_controller": "myBundle\Controller\GroupeController::showAction", "id": "3", "_route": "groupe_show") [] []
[2013-05-03 18:15:48] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". [] []
[2013-05-03 18:15:48] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". [] []
[2013-05-03 18:15:48] security.DEBUG: Read SecurityContext from the session [] []
[2013-05-03 18:15:48] security.DEBUG: Reloading user from user provider. [] []
[2013-05-03 18:15:48] doctrine.DEBUG: SELECT t0.username AS username1, t0.username_canonical AS username_canonical2, t0.email AS email3, t0.email_canonical AS email_canonical4, t0.enabled AS enabled5, t0.salt AS salt6, t0.password AS password7, t0.last_login AS last_login8, t0.locked AS locked9, t0.expired AS expired10, t0.expires_at AS expires_at11, t0.confirmation_token AS confirmation_token12, t0.password_requested_at AS password_requested_at13, t0.roles AS roles14, t0.credentials_expired AS credentials_expired15, t0.credentials_expire_at AS credentials_expire_at16, t0.id AS id17 FROM myUser t0 WHERE t0.id = ? LIMIT 1 [1] []
[2013-05-03 18:15:48] security.DEBUG: Username "toto" was reloaded from user provider. [] []
[2013-05-03 18:15:48] security.INFO: No expression found; abstaining from voting. [] []
[2013-05-03 18:15:48] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest". [] []
[2013-05-03 18:15:48] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\Fragment\FragmentHandler::onKernelRequest". [] []
[2013-05-03 18:15:48] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DeprecationLoggerListener::injectLogger". [] []
[2013-05-03 18:15:48] event.DEBUG: Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController". [] []
[2013-05-03 18:15:48] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController". [] []
[2013-05-03 18:15:48] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController". [] []
[2013-05-03 18:15:48] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController". [] []
[2013-05-03 18:15:48] event.DEBUG: Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController". [] []
[2013-05-03 18:15:48] doctrine.DEBUG: SELECT t0.id AS id1, t0.identity AS identity2, t0.confirmed AS confirmed3, t0.role AS role4, t0.groupe_id AS groupe_id5, t0.user_id AS user_id6 FROM AssociationUserGroupe t0 WHERE t0.groupe_id = ? LIMIT 1 ["3"] []
[2013-05-03 18:15:48] event.DEBUG: Notified event "kernel.view" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelView". [] []
[2013-05-03 18:15:48] doctrine.DEBUG: SELECT t0.id AS id1, t0.name AS name2, t0.description AS description3 FROM Groupe t0 WHERE t0.id = ? ["3"] []
[2013-05-03 18:15:48] doctrine.DEBUG: SELECT t0.id AS id1, t0.identity AS identity2, t0.confirmed AS confirmed3, t0.role AS role4, t0.groupe_id AS groupe_id5, t0.user_id AS user_id6 FROM AssociationUserGroupe t0 WHERE t0.groupe_id = ? [3] []

记录(刷新后)

[2013-05-03 18:16:05] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". [] []
[2013-05-03 18:16:05] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". [] []
[2013-05-03 18:16:05] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". [] []
[2013-05-03 18:16:05] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". [] []
[2013-05-03 18:16:05] request.INFO: Matched route "groupe_show" (parameters: "_controller": "myBundle\Controller\GroupeController::showAction", "id": "3", "_route": "groupe_show") [] []
[2013-05-03 18:16:05] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". [] []
[2013-05-03 18:16:05] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". [] []

这就是我得到的......

1 个答案:

答案 0 :(得分:0)

这可能是一个错误,但我通过运行PHP 5.3.20代替PHP 5.4.10解决了这个问题 如果有人有解释,我会很高兴看到它!