Giter Site home page Giter Site logo

interpunkt / meat-up Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 165 KB

Generates a Symfony CRUD Controller with a lof ot built in features based on a Doctrine Entity

License: MIT License

PHP 72.70% HTML 27.30%
symfony-bundle doctrine crud-generator

meat-up's Introduction

MeatUp Bundle

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.

meat-up's People

Contributors

daniellehrner avatar

Stargazers

Benjamin Knecht avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.