background preloader

Symfony

Facebook Twitter

The symfony and Doctrine book. In the previous chapters you've seen some various syntaxes for specifying your schema information in YAML files placed in config/doctrine.

The symfony and Doctrine book

This chapter explains the syntaxes and how to specify all your schema meta data in YAML format. Data Types Doctrine offers several column data types. When you specify the portable Doctrine type it is automatically converted to the appropriate type of the DBMS you are using. Below is a list of the available column types that can be used as well as the type it is translated to when using the MySQL and pgSQL DBMS engines. note Doctrine data types are standardized and made portable across all DBMS. Char(length) is used for string if "fixed" parameter is true. Below is a sample yaml schema file that implements each of the different column types.

Generates the following SQL with MySQL: Options Often you need to set options on your table for controlling things like charset, collation and table type in mysql. Indexes Relationships One to One One to Many Many to Many. Doctrine - Format SQL. Retrieving Data In Doctrine you are able to retrieve complex results from your RDBMS and hydrate them into array or object data structures which represent your relationship structure.

Doctrine - Format SQL

This is done by using the Doctrine Query Language. It is the best way to retrieve all your data in the lowest amount of queries possible. For convenience when working with single tables we offer some simple finder methods as well that dynamically build and execute these queries. Doctrine uses DQL for retrieving data and offers a complete Doctrine_Query API for building them. Query API Common API Select API Update API Delete API Create New Query Create new query from Doctrine_Table instance. $q = Doctrine::getTable('User')->createQuery('u') ->where('u.username = ? ' Create new query manually. Doctrine - YML. Alors comme ça, vous souhaitez essayer Doctrine avec symfony 1.1 ?

Doctrine - YML

Avant toute chose, nous allons créer un nouveau projet symfony 1.1 et installer le plugin sfDoctrinePlugin pour la 1.1. Exécutez ces quelques lignes de commandes, puis continuez la lecture : $ mkdir symfony1.1Doctrine $ cd symfony1.1Doctrine $ /path/to/symfony generate:project symfony1.1Doctrine $ svn co plugins/sfDoctrinePlugin $ php symfony cc Maintenant, tapez la commande suivante pour lister toutes les nouvelles fonctionnalités que sfDoctrinePlugin fournit. Vous noterez que cela génère les mêmes commandes que sfPropelPlugin, et bien plus encore ! Tout d'abord, sfDoctrinePlugin nécessite qu'au moins une application soit créée. . $ php symfony generate:app frontend Maintenant, configurons notre base de données dans config/databases.yml. All: doctrine: class: sfDoctrineDatabase param: dsn: echo dirname(__FILE__); ? Maintenant que notre schéma est défini, créons quelques données de tests dans data/fixtures/data.yml. Note $ $ Web PHP Framewor.