![]() |
|
The symfony and Doctrine bookChương 1 - Mở đầu |
|
You are currently reading "The symfony and Doctrine book" which is licensed under the GFDL license.

"Symfony & Doctrine book" không hướng dẫn chi tiết về Doctrine, chỉ đề cập đến một vài chủ đề thường dùng trong symfony. Doctrine manual vẫn là tài liệu tốt nhất để tìm hiểu mọi thứ về Doctrine. Tôi khuyên bạn đọc cuốn sách này để có thể bắt đầu với Doctrine và sau đó dùng Doctrine manual để tra cứu cụ thể cách dùng Doctrine. Bạn có thể tìm đọc tài liệu về Doctrine ở đây.

Doctrine là một PHP ORM (Object Relational Mapper) dành cho PHP 5.2.3+, và là một trong những PHP DBAL (DataBase Abstraction Layer) mạnh mẽ nhất. Một trong những tính năng quan trọng là khả năng viết câu truy vấn theo cách hướng đối tượng - cách truy vấn này được gọi là DQL(Doctrine Query Language, giống cách viết tắt của Hibernate's HQL).
Để sử dụng Doctrine, trước tiên bạn cần bật nó bằng cách sửa phương thức setup() của file config/ProjectConfiguration.class.php để enable sfDoctrinePlugin và disable sfPropelPlugin.
public function setup() { $this->enablePlugins(array('sfDoctrinePlugin')); $this->disablePlugins(array('sfPropelPlugin')); }
Nếu bạn muốn enable tất cả các plugin khác, bạn có thể làm như sau:
public function setup() { $this->enableAllPluginsExcept(array('sfPropelPlugin', 'sfCompat10Plugin')); }
Doctrine và Propel có thể hoạt động đồng thời, tuy nhiên việc này không được khuyến khích. Bạn có thể thực hiện điều này bằng cách enable sfDoctrinePlugin và không disable sfPropelPlugin.
Dưới đây là danh sách tất cả các tác vụ có thể thực hiện với sfDoctrinePlugin. sfDoctrinePlugin có tất cả các chức năng của sfPropelPlugin, và còn bổ sung thêm nhiều chức năng khác.
$ ./symfony list doctrine
Usage:
symfony [options] task_name [arguments]
Options:
--dry-run -n Do a dry run without executing actions.
--help -H Display this help message.
--quiet -q Do not log messages to standard output.
--trace -t Turn on invoke/execute tracing, enable full backtrace.
--version -V Display the program version.
Available tasks for the "doctrine" namespace:
:build-all Generates Doctrine model, SQL and initializes the database (doctrine-build-all)
:build-all-load Generates Doctrine model, SQL, initializes database, and load data (doctrine-build-all-load)
:build-all-reload Generates Doctrine model, SQL, initializes database, and load data (doctrine-build-all-reload)
:build-all-reload-test-all Generates Doctrine model, SQL, initializes database, load data and run all test suites (doctrine-build-all-reload-test-all)
:build-db Creates database for current model (doctrine-build-db)
:build-filters Creates filter form classes for the current model
:build-forms Creates form classes for the current model (doctrine-build-forms)
:build-model Creates classes for the current model (doctrine-build-model)
:build-schema Creates a schema from an existing database (doctrine-build-schema)
:build-sql Creates SQL for the current model (doctrine-build-sql)
:data-dump Dumps data to the fixtures directory (doctrine-dump-data)
:data-load Loads data from fixtures directory (doctrine-load-data)
:dql Execute a DQL query and view the results (doctrine-dql)
:drop-db Drops database for current model (doctrine-drop-db)
:generate-admin Generates a Doctrine admin module
:generate-migration Generate migration class (doctrine-generate-migration)
:generate-migrations-db Generate migration classes from existing database connections (doctrine-generate-migrations-db, doctrine-gen-migrations-from-db)
:generate-migrations-models Generate migration classes from an existing set of models (doctrine-generate-migrations-models, doctrine-gen-migrations-from-models)
:generate-module Generates a Doctrine module (doctrine-generate-crud, doctrine:generate-crud)
:generate-module-for-route Generates a Doctrine module for a route definition
:insert-sql Inserts SQL for current model (doctrine-insert-sql)
:migrate Migrates database to current/specified version (doctrine-migrate)
:rebuild-db Creates database for current model (doctrine-rebuild-db)
If you find a typo or an error, please register and open a ticket.
If you need support or have a technical question, please post to the official user mailing-list.