0

这是问题:我没有成功安装 stof bundle with symphony 2.0

我如何进行:

我在 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#include-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

我做错了什么?

4

2 回答 2

1

我想说这些错误与 Symfony 或 Doctrine 无关。对我来说,这更像是一个 PHP 配置问题。

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

于 2012-10-13T19:13:01.967 回答
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

于 2012-10-13T18:00:37.070 回答