propel-bundle/Resources/doc/index.markdown
Rafael Dohms c87af30b1b Update index.markdown
Updated installation instructions via composer to use the `composer require` command without specifying a version.
This is the new recommended way of providing this information and it leads to composer picking the proper version constraint (i.e ~1.2), updating the `composer.json` and running install, all in one command.
2014-10-31 17:18:07 +01:00

3.7 KiB

PropelBundle

This is the official implementation of Propel in Symfony2.

Installation

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

composer require propel/propel-bundle

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] [--connection[=""]]

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

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

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.