0

わかりました、私はJoel Verhagenの方針に沿って Codeigniter で Doctrine2 を使用しており、問題なく動作していますが、今は不思議な問題があります。

アイテムを破壊するとき、物事はうまくいきます:

$delete = $this->doctrine->em->getRepository('Entities\Item')->findOneBy(array('slug' => $item));
$this->doctrine->em->remove($delete);
$this->doctrine->em->flush();

しかし、アイテムの更新は、getRepository() の直後にサイレントに失敗します。

$item = $this->doctrine->em->getRepository('Entities\Item')->findOneBy(array('id' => $id));
$item->setDescription(html_entity_decode($_POST['content']));
$this->doctrine->em->persist($item);
$this->doctrine->em->flush();

同じコントローラーで、それが各アクションのすべてのコードです。他のすべてのコントローラーは問題ありませんが、これはログに何も記録されずに失敗します。getRepository と find 呼び出しを分割すると、getRepository の直後に停止します。getRepository を __construct に移動すると、update() が検索で終了します。

考え?リード?SOの他の誰かが別の方向に進んでいるか、問題を解決していないようです。

ありがとう!


編集:モデルを追加

ヤムル

アイテム

Entities\Item:
    type: entity
    table: items
    id:
        id:
            type: integer
            primary: true
            notnull: true
            generator:
                strategy: AUTO
    fields:
        title:
            type: string(255)
            notnull: true
        slug:
            type: string(255)
            notnull: true
        description:
            type: string(255)
    manyToOne:
        type:
            targetEntity: Type
            inversedBy: item
            joinColumn:
                name: type_id
                referencedColumnName: id
    options:
        charset: utf8
        type: InnoDB

タイプ

Entities\Type:
    type: entity
    table: types
    id:
        id:
            type: integer
            primary: true
            notnull: true
            generator:
                strategy: AUTO
    fields:
        title:
            type: string(255)
            notnull: true
        slug:
            type: string(255)
            notnull: true
        description:
            type: string(255)
    oneToMany:
        items:
            targetEntity: Item
            orphanRemoval: true
            mappedBy: type
    manyToMany:
        fields:
            targetEntity: Field
            inversedBy: types
            joinTable:
                name: fields_types
                joinColumns:
                    type_id:
                        referencedColumnName: id
                inverseJoinColumns:
                    field_id:
                        referencedColumnName: id
    options:
        charset: utf8
        type: InnoDB

PHP

アイテム

<?php

namespace Entities;

use Doctrine\ORM\Mapping as ORM;

/**
 * Entities\Item
 */
class Item
{
    /**
     * @var integer $id
     */
    private $id;

    /**
     * @var string $title
     */
    private $title;

    /**
     * @var string $description
     */
    private $description;

    /**
     * @var \Doctrine\Common\Collections\ArrayCollection
     */
    private $fields;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->fields = new \Doctrine\Common\Collections\ArrayCollection();
    }

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

    /**
     * Set title
     *
     * @param string $title
     * @return Item
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Add fields
     *
     * @param Entities\Field $fields
     * @return Item
     */
    public function addField(\Entities\Field $fields)
    {
        $this->fields[] = $fields;

        return $this;
    }

    /**
     * Remove fields
     *
     * @param Entities\Field $fields
     */
    public function removeField(\Entities\Field $fields)
    {
        $this->fields->removeElement($fields);
    }

    /**
     * Get fields
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getFields()
    {
        return $this->fields;
    }
    /**
     * @var Entities\Type
     */
    private $types;


    /**
     * Set types
     *
     * @param Entities\Type $types
     * @return Item
     */
    public function setTypes(\Entities\Type $types = null)
    {
        $this->types = $types;

        return $this;
    }

    /**
     * Get types
     *
     * @return Entities\Type 
     */
    public function getTypes()
    {
        return $this->types;
    }
    /**
     * @var Entities\Type
     */
    private $type;


    /**
     * Set type
     *
     * @param Entities\Type $type
     * @return Item
     */
    public function setType(\Entities\Type $type = null)
    {
        $this->type = $type;

        return $this;
    }

    /**
     * Get type
     *
     * @return Entities\Type 
     */
    public function getType()
    {
        return $this->type;
    }
    /**
     * @var string $slug
     */
    private $slug;


    /**
     * Set slug
     *
     * @param string $slug
     * @return Item
     */
    public function setSlug($slug)
    {
        $this->slug = $slug;

        return $this;
    }

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

タイプ

<?php

namespace Entities;

use Doctrine\ORM\Mapping as ORM;

/**
 * Entities\Type
 */
class Type
{
    /**
     * @var integer $id
     */
    private $id;

    /**
     * @var string $title
     */
    private $title;

    /**
     * @var string $description
     */
    private $description;

    /**
     * @var \Doctrine\Common\Collections\ArrayCollection
     */
    private $items;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->items = new \Doctrine\Common\Collections\ArrayCollection();
    }

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

    /**
     * Set title
     *
     * @param string $title
     * @return Type
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Add items
     *
     * @param Entities\Item $items
     * @return Type
     */
    public function addItem(\Entities\Item $items)
    {
        $this->items[] = $items;

        return $this;
    }

    /**
     * Remove items
     *
     * @param Entities\Item $items
     */
    public function removeItem(\Entities\Item $items)
    {
        $this->items->removeElement($items);
    }

    /**
     * Get items
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getItems()
    {
        return $this->items;
    }
    /**
     * @var \Doctrine\Common\Collections\ArrayCollection
     */
    private $fields;


    /**
     * Add fields
     *
     * @param Entities\Field $fields
     * @return Type
     */
    public function addField(\Entities\Field $fields)
    {
        $this->fields[] = $fields;

        return $this;
    }

    /**
     * Remove fields
     *
     * @param Entities\Field $fields
     */
    public function removeField(\Entities\Field $fields)
    {
        $this->fields->removeElement($fields);
    }

    /**
     * Get fields
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getFields()
    {
        return $this->fields;
    }
    /**
     * @var string $slug
     */
    private $slug;


    /**
     * Set slug
     *
     * @param string $slug
     * @return Type
     */
    public function setSlug($slug)
    {
        $this->slug = $slug;

        return $this;
    }

    /**
     * Get slug
     *
     * @return string 
     */
    public function getSlug()
    {
        return $this->slug;
    }
}
4

1 に答える 1

-1

それを私が直した。残念ながら、その理由はわかりません。なぜこれがそれを修正するのか(または最初に何が壊れていたのか)誰かが私に説明できるなら、私はあなたの答えを受け入れます。

アイテムリポジトリをロードすると、サイレントに失敗します。Typeリポジトリをロードし、それに対してfindAllを実行すると、最初にそれが修正されました。これはすべて、ItemsがTypeの子であるためである可能性がありますが、特定のItemをロードできるようにするためだけに、事前にfindAll()を実行する必要があるのは奇妙に思えます。

たとえば、これを__construct()で実行します。

$this->typeR = $this->doctrine->em->getRepository('Entities\Type');
$data['types'] = $this->typeR->findAll();
$this->itemR = $this->doctrine->em->getRepository('Entities\Item');

そのコントローラーに必要なときにいつでもアイテムをロードできます。

繰り返しますが、これはサーバー上にありました。ローカルでは、すべて正常に機能しました。

于 2012-11-06T20:47:23.770 に答える