This bundle extends the commands provided by SensioGeneratorBundle, adding a MongoDB document generator and CRUD generators for those MongoDB documents.
Add the requirement to composer:
$ php composer.phar require ismaambrosi/generator-bundle
You will also need to install the DoctrineMongoDBBundle. The instructions on how to install it are available in the Symfony2 documentation.
<?php
// app/AppKernel.php
public function registerBundles()
{
// ...
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
// ...
$bundles[] = new IsmaAmbrosi\Bundle\GeneratorBundle\IsmaAmbrosiGeneratorBundle();
}
}
It is recommended to disable this bundle for the production environment.
This bundle contains three commands that will allow you to generate code for documents, forms and CRUD controllers. These commands can be executed either on interactive mode or manual mode. I would recommend you to use the interactive mode.
The first command allows to generate the document classes.
Examples:
$ php app/console doctrine:mongodb:generate:document
$ php app/console doctrine:mongodb:generate:document \
--document=AcmeBlogBundle:Blog/Post \
--with-repository
With the second command we can generate the form type classes, used by the form component.
Example:
$ php app/console doctrine:mongodb:generate:form AcmeBlogBundle:Post
The last command generates the CRUD controllers, with read-only actions to handle the documents that were generated previously. It also allows to include the write actions, for creating, updating and deleting documents.
Examples:
$ php app/console doctrine:mongodb:generate:crud
# Specifying the document and the routing prefix
$ php app/console doctrine:mongodb:generate:crud \
--document=AcmeBlogBundle:Post \
--route-prefix=post_admin
# Specifying the document, routing and write-actions
$ php app/console doctrine:mongodb:generate:crud \
--document=AcmeBlogBundle:Post \
--route-prefix=post_admin --with-write