这是问题:我没有成功安装带有交响乐 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/供应商安装 --重新安装
一切都很好。
然后我在相关文件中激活扩展名
# 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 SymfonyComponentHttpKernelKernel;
use SymfonyComponentConfigLoaderLoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
[...]
new StofDoctrineExtensionsBundleStofDoctrineExtensionsBundle(),
[...]
);
# autoload.php
use SymfonyComponentClassLoaderUniversalClassLoader;
use DoctrineCommonAnnotationsAnnotationRegistry;
$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 MyprojectMyBundleEntity;
use GedmoMappingAnnotation as Gedmo;
use DoctrineORMMapping as ORM;
/**
* @GedmoTree(type="nested")
* @ORMTable(name="Category")
* use repository for handy tree functions
* @ORMEntity(repositoryClass="GedmoTreeEntityRepositoryNestedTreeRepository")
*/
class Category
{
/**
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue
*/
private $id;
/**
* @ORMColumn(name="title", type="string", length=64)
*/
private $title;
/**
* @GedmoTreeLeft
* @ORMColumn(name="lft", type="integer")
*/
private $lft;
/**
* @GedmoTreeLevel
* @ORMColumn(name="lvl", type="integer")
*/
private $lvl;
/**
* @GedmoTreeRight
* @ORMColumn(name="rgt", type="integer")
*/
private $rgt;
/**
* @GedmoTreeRoot
* @ORMColumn(name="root", type="integer", nullable=true)
*/
private $root;
/**
* @GedmoTreeParent
* @ORMManyToOne(targetEntity="Category", inversedBy="children")
* @ORMJoinColumn(name="parent_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $parent;
/**
* @ORMOneToMany(targetEntity="Category", mappedBy="parent")
* @ORMOrderBy({"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
我做错了什么?
说这些错误与Symfony或Doctrine无关。对我来说,这更像是一个PHP配置问题。
您可以尝试增加php.ini
文件中的memory_limit
值。在大多数情况下,128MB 的内存限制就足够了,但如果您的项目正在处理大量数据,则可能需要更多。
尝试只加载树扩展:
doctrine:
orm:
entity_managers:
default:
mappings:
gedmo_tree:
type: annotation
prefix: GedmoTreeEntity
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