Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 128 lines (86 sloc) 3.775 kb

PropelBundle

This is the official implementation of Propel in Symfony2.

Installation

The recommended way to install this bundle is to rely on Composer:

{
    "require": {
        // ...
        "propel/propel-bundle": "1.1.*"
    }
}

Otherwise you can use Git, SVN, Git submodules, or the Symfony vendor management (deps file):

The second step is to register this bundle in the AppKernel class:

public function registerBundles()
{
    $bundles = array(
        // ...
        new Propel\PropelBundle\PropelBundle(),
    );

    // ...
}

Don't forget to register the PropelBundle namespace in app/autoload.php if you are not using Composer:

$loader->registerNamespaces(array(
    // ...
    'Propel' => __DIR__.'/../vendor/bundles',
));
$loader->registerPrefixes(array(
    // ...
    'Phing'  => __DIR__.'/../vendor/phing/classes/phing',
));

You are almost ready, the next steps are:

Now, you can build your model classes, and SQL by running the following command:

> php app/console propel:build [--classes] [--sql] [--insert-sql]

To insert SQL statements, use the propel:sql:insert command:

> php app/console propel:sql:insert [--force]

Note that the --force option is needed to actually execute the SQL statements.

Congratulation! You're done, just use the Model classes as any other class in Symfony2:

<?php

class HelloController extends Controller
{
    public function indexAction($name)
    {
        $author = new \Acme\DemoBundle\Model\Author();
        $author->setFirstName($name);
        $author->save();

        return $this->render('AcmeDemoBundle:Hello:index.html.twig', array(
            'name' => $name, 'author' => $author)
        );
    }
}

Now you can read more about:

Bundle Inheritance

The PropelBundle makes use of the bundle inheritance. Currently only schema inheritance is provided.

Schema Inheritance

You can override the defined schema of a bundle from within its child bundle. To make use of the inheritance you only need to drop a schema file in the Resources/config folder of the child bundle.

Each file can be overridden without interfering with other schema files. If you want to remove parts of a schema, you only need to add an empty schema file.

Something went wrong with that request. Please try again.