安装stof bundle和doctrine扩展时出现致命错误(树)

时间:2012-10-13 14:32:24

标签: symfony doctrine-orm symfony-2.0 doctrine-extensions

问题在于:我没有成功安装 symphony 2.0

的stof包

我如何继续:

我在deps文件中添加以下行:

[GedmoDoctrineExtensions]
    git=https://github.com/l3pp4rd/DoctrineExtensions.git
    target=bundles/gedmo-doctrine-extensions
    version=e93fc1e0a0

[StofDoctrineExtensionsBundle]
    git=https://github.com/stof/StofDoctrineExtensionsBundle.git
    target=bundles/Stof/DoctrineExtensions/Bundle
    version=6b2a8c74bd

然后我运行命令

php bin / vendors install --reinstall

一切都很好。

然后我在相关文件中激活扩展

# config.yml
stof_doctrine_extensions:
    default_locale: en_US
    orm:
        default:
            tree: true

orm:
    auto_generate_proxy_classes: %kernel.debug%
    auto_mapping: true
    mappings:
        StofDoctrineExtensionsBundle: ~

# AppKernel.php    
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            [...]
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
            [...]
        );

# autoload.php
use Symfony\Component\ClassLoader\UniversalClassLoader;
use Doctrine\Common\Annotations\AnnotationRegistry;

$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
    'Gedmo'            => __DIR__.'/../vendor/gedmo-doctrine-extensions/lib',
    'Stof'             => __DIR__.'/../vendor/bundles', 
    [...]
    ));

最后,我添加了我的实体类别,如本教程http://gediminasm.org/article/tree-nestedset-behavior-extension-for-doctrine-2#including-extension

<?php
namespace Myproject\MyBundle\Entity;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;

/**
 * @Gedmo\Tree(type="nested")
 * @ORM\Table(name="Category")
 * use repository for handy tree functions
 * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
 */
class Category
{
    /**
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue
     */
    private $id;

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

    /**
     * @Gedmo\TreeLeft
     * @ORM\Column(name="lft", type="integer")
     */
    private $lft;

    /**
     * @Gedmo\TreeLevel
     * @ORM\Column(name="lvl", type="integer")
     */
    private $lvl;

    /**
     * @Gedmo\TreeRight
     * @ORM\Column(name="rgt", type="integer")
     */
    private $rgt;

    /**
     * @Gedmo\TreeRoot
     * @ORM\Column(name="root", type="integer", nullable=true)
     */
    private $root;

    /**
     * @Gedmo\TreeParent
     * @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="SET NULL")
     */
    private $parent;

    /**
     * @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
     * @ORM\OrderBy({"lft" = "ASC"})
     */
    private $children;
}

但是当我运行命令php app / console generate:doctrine:entities MyProjectMyBundle:Category时,我有以下错误:

Fatal error: Out of memory (allocated -1227096064) (tried to allocate 261900 bytes) in /home/user/Project/vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php on line 75

有时这一个:

Fatal error: Out of memory (allocated -1222901760) (tried to allocate 261900 bytes) in /home/user/Project/vendor/gedmo-doctrine-extensions/lib/Gedmo/Mapping/MappedEventSubscriber.php on line 176

我做错了什么?

2 个答案:

答案 0 :(得分:1)

我会说这些错误与Symfony和Doctrine无关。对我而言,它更像是PHP配置问题。

您可以尝试增加memory_limit文件中的php.ini值。在大多数情况下,内存限制为128MB就足够了,但如果您的项目处理大量数据,则可能需要更多。

答案 1 :(得分:0)

尝试仅加载树扩展:

doctrine:
    orm:
        entity_managers:
            default:
                mappings:
                    gedmo_tree:
                       type: annotation
                       prefix: Gedmo\Tree\Entity
                       dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
                       alias: GedmoTree # this one is optional and will default to the name set for the mapping
                       is_bundle: false

正如文档所说:https://github.com/stof/StofDoctrineExtensionsBundle/blob/master/Resources/doc/index.rst#add-the-extensions-to-your-mapping