2

我正在学习 symfony2 并为此制作演示示例。

当我试图在命令下运行时。

$php 应用程序/控制台原则:生成:实体 HelloBundle

它工作正常。但它会生成所有实体。

但如果我想生成特定的实体,那么

$php 应用程序/控制台原则:generate:entities HelloBundle --entity="User"

它给出了以下错误

$ php 控制台原则:generate:entities HelloBundle --entity="Messages"
为“HelloBundle”生成实体

PHP 致命错误:在第 63 行的 /home/prakash/web/Symfony/vendor/symfony/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php 中的非对象上调用成员函数 getShortName()
4

1 回答 1

2

Old question, but I've just been doing this!

It seems you're using Linux, so open up a Terminal, cd to Symfony's app directory, then run ./console --shell.

This'll bring up the interactive shell where you can run through commands piecemeal, which I've found a little more helpful if not a bit slower.

When the shell is open, type doctrine:generate:entity and it'll run you through a little wizard where you can create a single entity for a specific bundle. It'll ask you first for the name, eg. HelloBundle:EntityName, then it'll ask for the syntax to use (yml, xml, annotation) and then it will let you enter the fields and their types.

After doing that (if you want), and hitting return when the field name is blank, it'll ask you if you want to generate the repository class for the entity, and finally make sure you want to generate it all. Hit return again and your entity files will be made.

I tried the single line command way as described in the OP but got strange errors (may have done it wrong), however it may be a simple case of taking that command and replacing entities with entity.

more info: http://symfony.com/doc/current/book/doctrine.html

于 2011-07-09T21:08:24.700 回答