daniellehrner/meat-up

Code generator for Symfony2

Installs: 20

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Type:symfony-bundle

v0.6.0 2017-07-26 05:11 UTC

This package is not auto-updated.

Last update: 2024-04-26 22:32:20 UTC


README

The MeatUp Bundle is a Symfony bundle that provides a command for generating a CRUD controller based on a Doctrine Entity. It uses the Symfony Skeleton Application from inter-Punkt as a starting basis. The bundle will generate the following files for you:

  • A FormType based on a Doctrine Entity and some of MeatUps annotations
  • A Controller for the CRUD operations
  • A view file for a tabular presentation of all records
  • View files for creating and updating records

Basic Usage

This guide will show you who to generate a CRUD Controller from a simple Doctrine entity.

Here is a summary of what you will have to do:

Step 1: Create a simple Doctrine entity

<?php
// File: src/DevPro/adminBundle/Entity/Meatup.php

namespace DevPro\adminBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Meatup
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
    
    /**
     * @ORM\Column(type="string")
     */
    private $title;
    
    /**
     * @ORM\Column(type="text")
     */
    private $content;
    
    ...
}

The example above is a very basic Doctrine entity. If you don't understand everything in there, you can find more information in the Doctrine documentation.

Now you can use a Doctrine command to create the getter and setter methods for you:

$ php app/console doctrine:generate:entities DevProadminBundle:Meatup

Now the entity class is complete and you can create the table in the database:

$ php app/console doctrine:schema:update --force

Step 2: Execute the MeatUp command

Now everything is ready for the MeatUp command to generate your CRUD controller with the the fully qualified class name as argument:

$ php app/console ip:meat-up "DevPro\adminBundle\Entity\Meatup"

After the command has successfully finished you can start your web server and check out the controller. If you don't know how you can start the built-in Web-Server have a look at the Symfony documentation.

If your Web-server is running as localhost:8000 just enter the following URL in your browser:

http://localhost:8000/admin/meatup

You can now go on and create a new record by clicking on the button with the label 'Neuer Eintrag'. After creating the new record you will be redirected to the overview page. There you will see that there is a new record and that you can edit it with a click on the button 'Bearbeiten', but there is no column yet to indicate which record it is.

Step 3: Add OnIndex annotation

Because there is no way for the MeatUp command to guess which properties of your entities you want to show on the overview page, you need to add the OnIndex annotation to tell the bundle that this property should be on it. Luckily we only need to add two lines to the entity above to do that.

First we need to import the MeatUp namespace and add an alias to it:

...
use Doctrine\ORM\Mapping as ORM;
use Ip\MeatUp\Mapping as MU;
...

Now we add the OnIndex annotation to the title property:

...
    /**
    * @ORM\Column(type="string")
    * @MU\OnIndexPage
    */
    private $title;
...

That's it! Now we execute the MeatUp command once more and after reloading the website the title will be shown on the overview page with the record we created before:

$ php app/console ip:meat-up "DevPro\adminBundle\Entity\Meatup"

You now know already how to use the MeatUp command to create simple CRUD controllers. For more advanced usages please refer to the docs.

Usage

For the full usage documentation see:

Resources/doc/index.md

Requirements

License

See the bundled LICENSE file.