2017 © Pedro Peláez
 

symfony-bundle demo-bundle

Demo Bundle

image

dataspring/demo-bundle

Demo Bundle

  • Tuesday, April 11, 2017
  • by Guobin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Create your own Symfony2 bundle

Tutorial of creating your own Symfony2 bundle, (*1)

How to do?

1. Install Symfony

http://symfony.cn/docs/quick_tour/the_big_picture.html, (*2)

2. Create a new empty symfony project

symfony new DemoBundle 2.3 

(2.3 is my symfony version), (*3)

3. Enter into the project directory

cd DemoBundle

4. Generate a new bundle

php app/console generate:bundle

this will ask you to answer questions. For Bundle namespace set to DataSpring/DemoBundle (CompanyName / BundleName)., (*4)

5. Enter into the bundle directory

cd src/DataSpring/DemoBundle

6. Init your github repository

Create a new repository in your github first then run the following command lines:, (*5)

git init 
touch README.md
git add .
git commit -m "initial commit"
git remote add origin git@github.com:YourAccount/DemoBundle.git
git push -u origin master

7. Add a composer.json file

In the src/DataSpring/DemoBundle/ folder, manually add a composer.json file., (*6)

or run, (*7)

composer init

to get a simpliest file before changing it., (*8)


, (*9)

A composer.json file would look like so:, (*10)

{
    "name": "dataspring/demo-bundle",
    "description": "Demo Bundle",
    "type": "symfony-bundle",
    "keywords": ["dataspring"],
    "license": "MIT",
    "homepage": "http://github.com/guobinqiu/DemoBundle",
    "authors": [
        {
            "name": "Guobin",
            "email": "qracle@126.com"
        }
    ],
    "require": {
        "php": "~5.3"
    },
    "autoload": {
        "psr-4": {
            "DataSpring\\DemoBundle\\": ""
        }
    },
    "extra": {
        "branch-alias": {
            "dev-master": "0.1.x-dev"
        }
    }
}

8. Add a MIT license file

In the src/DataSpring/DemoBundle/ folder, add a LICENSE file, (*11)

https://opensource.org/licenses/MIT, (*12)

Your can borrow from the above licence reference as your own license content. Also see LICENSE, (*13)

9. Create a controller and its routing

Controller Code:, (*14)

<?php

namespace Dataspring\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
    public function indexAction()
    {
        return $this->render('DataSpringDemoBundle:Default:index.html.twig');
    }
}

In the src/Resources/config/routing.yml to add:, (*15)

demo_index:
    path:      /index
    defaults:  { _controller: DataSpringDemoBundle:Default:index }

Notice that when creating your own bundle, Annotation way is not supported!, (*16)

10. Tag/Release it in the Github

git tag -a VERSION -m "MESSAGE"
git push origin VERSION

or Release in Github, (*17)

11. Put it in the Packagist

Use it in another project

1. Add Composer Dependencies

Add it to the composer.json file:

{
    ...,
    "require": {
        ...,
        "dataspring/demo-bundle": "^0.1.4"
    }
}

Update the dependency

php composer.phar update dataspring/demo-bundle

or update all dependencies, (*21)

php composer.phar update

or you can do this in one command:, (*22)

php composer.phar require dataspring/demo-bundle

2. Enable the Bundle

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            ...,
            new DataSpring\DemoBundle\DataSpringDemoBundle()
        );
        ...
    }
}

3. Add into your project main routing file

data_spring_demo:
    resource: "@DataSpringDemoBundle/Resources/config/routing.yml"
    prefix:   /demo

4. Finally

Typing http://YourDomain:port/demo/index in your web browser to access!, (*23)

The Versions

11/04 2017

dev-master

9999999-dev http://github.com/guobinqiu/DemoBundle

Demo Bundle

  Sources   Download

MIT

The Requires

  • php ~5.3

 

by Avatar Guobin

dataspring

05/05 2016

0.1.5

0.1.5.0 http://github.com/guobinqiu/DemoBundle

Demo Bundle

  Sources   Download

MIT

The Requires

  • php ~5.3

 

by Avatar Guobin

dataspring

04/05 2016

0.1.4

0.1.4.0 http://github.com/guobinqiu/DemoBundle

Demo Bundle

  Sources   Download

MIT

The Requires

  • php ~5.3

 

by Avatar Guobin

dataspring

20/04 2016

0.1.3

0.1.3.0 http://github.com/guobinqiu/DemoBundle

Demo Bundle

  Sources   Download

MIT

The Requires

  • php ~5.3

 

by Avatar Guobin

dataspring

19/04 2016

0.1.2

0.1.2.0 http://github.com/guobinqiu/DemoBundle

Demo Bundle

  Sources   Download

MIT

The Requires

  • php ~5.3

 

by Avatar Guobin

dataspring

19/04 2016

0.1.1

0.1.1.0 http://github.com/guobinqiu/DemoBundle

Demo Bundle

  Sources   Download

MIT

The Requires

  • php ~5.3

 

by Avatar Guobin

dataspring

19/04 2016

0.1.0

0.1.0.0 http://github.com/guobinqiu/DemoBundle

test

  Sources   Download

The Requires

 

by Avatar Guobin

dataspring