开发者

Troubleshooting "Call to a member function on a non-object" when generating a single entity

开发者 https://www.devze.com 2023-02-17 09:56 出处:网络
I am studying symfony2 and make demo example for that. When i am trying to run below command. $php app/console doctrine:generate:entities HelloBundle

I am studying symfony2 and make demo example for that.

When i am trying to run below command.

$php app/console doctrine:generate:entities HelloBundle

its works fine. but its generate all then entities.

but if i want to generate particular one entities then

$php app/console doctrine:generate:entities HelloBundle --entity="User"

it gives below error

$ php console doctrine:generate:entities HelloBundle --entity="Messages"
Generating entities for "HelloBundle"

PHP Fatal error:  Call to a member function getShortName() on a non-object in /ho开发者_JAVA百科me/prakash/web/Symfony/vendor/symfony/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php on line 63


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

0

精彩评论

暂无评论...
验证码 换一张
取 消