Git Product home page Git Product logo

aminin / sfdoctrine2plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from maxim-oleinik/sfdoctrine2plugin

1.0 2.0 1.0 1.09 MB

The "upstream" branch is a git mirror of the sfDoctrine2Plugin subversion repository, updated daily. The "master" branch is my fork of the sfDoctrine2Plugin, containing bug fixes and features that I plan on submitting upstream.

Home Page: http://www.symfony-project.org/blog/2009/10/05/symfony-and-doctrine-2

PHP 100.00%

sfdoctrine2plugin's Introduction

# sfDoctrinePlugin 2.0

## Installing

Install the plugin as Git submodule:

    $ git submodule add git://github.com/maxim-oleinik/sfDoctrine2Plugin.git plugins/sfDoctrine2Plugin

    // Init plugins submodules
    $ cd plugins/sfDoctrine2Plugin/lib/vendor/doctrine2
    $ git submodule update --init

Now you just need to enable the plugin in your ProjectConfiguration:

    [php]
    class ProjectConfiguration extends sfProjectConfiguration
    {
      public function setup()
      {
        $this->enablePlugins('sfDoctrine2Plugin');
      }

      /**
       * Setup sfDoctrine2Plugin
       * Customize generator properties
       */
      public function setupPlugins()
      {
        sfConfig::set('sf_generator_proxy_dir', sfConfig::get('sf_lib_dir').'/App/Model/Proxy');
        sfConfig::set('sf_generator_proxy_ns',  'App\Model\Proxy');
        sfConfig::set('sf_generator_form_dir',  sfConfig::get('sf_lib_dir').'/App/Form');
        sfConfig::set('sf_generator_form_ns',   'App\Form');
      }
    }

## Configure Databases

Sample `databases.yml` for MySQL:

    [yml]
    all:
      doctrine:
        class: sfDoctrineDatabase
        param:
          options:
            driver: pdo_mysql
            user: root
            password:
            dbname: doctrine

Sample `databases.yml` for Sqlite:

    [yml]
    all:
      doctrine:
        class: sfDoctrineDatabase
        param:
          options:
            driver: pdo_sqlite
            path: %SF_DATA_DIR%/database.sqlite

## Schema Files

You can specify your schema files in `config/doctrine` just like normal. The schema syntax
is slightly different from Doctrine 1. Below is an example:

    [yml]
    Entities\User:
      type: entity
      table: user
      id:
        id:
          type: integer
          generator:
            strategy: AUTO
      fields:
        username:
          type: string
          length: 255
        password:
          type: string
          length: 255

## Custom Repository Class

You can configure a custom repository class so you can add new methods for
executing and retrieving queries.

    [yml]
    Entities\User:
      type: entity
      table: user
      repositoryClass: UserRepository
    # ...

Now define a `UserRepository` class:

    [php]
    class UserRepository extends EntityRepository
    {
      public function getActiveUsers()
      {
        $qb = $this->createQueryBuilder('u');
        $q = $qb->getQuery();

        return $q->execute();
      }
    }

Now you can use this method like the following:

    [php]
    $repository = $em->getRepository('Entities\User');
    $users = $repository->getActiveUsers();


## Data Fixtures

YAML data fixtures no longer exist in Doctrine 2. Instead we just
use regular PHP code to load our data fixtures.

    [php]
    // data/fixtures/fixtures.php

    $em = $this->getEntityManager();

    $admin = new \Entities\User();
    $admin->username = 'admin';
    $admin->password = 'changeme';

The `$em` variable that is defined in the fixture files is the entity manager that
will be used to persist the entities.

## Building Doctrine

Build models, forms, filters, database and load data fixtures.

    $ php symfony doctrine:build --all --and-load

## Updating Schema

Updating your schema is just a matter of changing your mapping information in
`config/doctrine` and then running the following command:

    $ php symfony doctrine:build --all-classes --and-update-schema

## Entity Manager in Actions

    [php]
    class usersActions extends sfActions
    {
      public function executeIndex()
      {
        $em = $this->getEntityManager();
        $qb = $em->createQueryBuilder();

        // ...
      }
    }

## Migrations

See http://www.doctrine-project.org/projects/migrations/2.0/docs/reference/introduction/en
Symfony tasks:

    $ ./symfony list migrations

Custom config

    $ cp ./plugins/sfDoctrine2Plugin/config/migrations.yml config/migrations.yml

sfdoctrine2plugin's People

Contributors

maxim-oleinik avatar

Stargazers

Anton Minin avatar

Watchers

Anton Minin avatar James Cloos avatar

Forkers

jayesbe

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.