Persistence in PHP with Doctrine ORM

Book description

This book is designed for PHP developers and architects who want to modernize their skills through better understanding of Persistence and ORM. You’ll learn through explanations and code samples, all tied to the full development of a web application.

  • Develop a fully functional Doctrine-backed web application
  • Demonstrate aspects of Doctrine using code samples
  • Generate a database schema from your PHP classes

In Detail

Doctrine 2 has become the most popular modern persistence system for PHP. It can either be used as a standalone system or can be distributed with Symfony 2, and it also integrates very well with popular frameworks. It allows you to easily retrieve PHP object graphs, provides a powerful object-oriented query language called DQL, a database schema generator tool, and supports database migration. It is efficient, abstracts popular DBMS, and supports PHP 5.3 features.

Doctrine is a must-have for modern PHP applications.

Persistence in PHP with Doctrine ORM is a practical, hands-on guide that describes the full creation process of a web application powered by Doctrine. Core features of the ORM are explained in depth and illustrated by useful, explicit, and reusable code samples.

Persistence in PHP with Doctrine ORM explains everything you need to know to get started with Doctrine in a clear and detailed manner.

From installing the ORM through Composer to mastering advanced features such as native queries, this book is a full overview of the power of Doctrine. You will also learn a bunch of mapping annotations, create associations, and generate database schemas from PHP classes. You will also see how to write data fixtures, create custom entity repositories, and issue advanced DQL queries. Finally it will teach you to play with inheritance, write native queries, and use built-in lifecycle events. If you want to use a powerful persistence system for your PHP application, Persistence in PHP with Doctrine ORM is the book you.

Table of contents

  1. Persistence in PHP with Doctrine ORM
    1. Table of Contents
    2. Persistence in PHP with Doctrine ORM
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Getting Started with Doctrine 2
      1. Prerequisites
      2. Understanding the concepts behind Doctrine
      3. Creating a project structure
      4. Installing Composer
      5. Installing Doctrine
      6. Bootstrapping the app
      7. Using Doctrine's Entity Manager
      8. Configuring Doctrine command-line tools
      9. Summary
    9. 2. Entities and Mapping Information
      1. Creating the Entity class
      2. Generating getters and setters
      3. Mapping with Doctrine annotations
        1. Knowing about the @Entity annotation
        2. Understanding the @Table, @Index, and @UniqueConstraint annotations
        3. Diving into the @Column annotation
        4. Knowing about the @Id and @GeneratedValue annotations
        5. Using other annotations
      4. Understanding Doctrine Mapping Types
      5. Creating the database schema
      6. Installing Data fixtures
      7. Creating a simple UI
        1. Listing posts
        2. Creating and editing posts
        3. Deleting posts
      8. Summary
    10. 3. Associations
      1. Getting started with the Doctrine associations
      2. Understanding the @ManyToOne and @OneToMany annotations with the comment system
        1. Creating the Comment entity class (owning side)
        2. Adding the inverse side to the Post entity class
        3. Updating the database schema
        4. Adding fixtures for the comments
        5. Listing and creating comments
        6. Updating the index
      3. Understanding the @ManyToMany annotation with tags
        1. Creating the Tag entity class (inverse side)
        2. Updating the Post entity class (owning side)
        3. Updating the schema again
        4. Creating tag fixtures
        5. Managing the tags of a post
      4. Summary
    11. 4. Building Queries
      1. Understanding DQL
      2. Using the entity repositories
        1. Creating custom entity repositories
      3. Getting started with Query Builder
      4. Filtering by tag
      5. Counting comments
      6. Summary
    12. 5. Going Further
      1. Implementing inheritance
        1. Using Mapped Superclasses
        2. Using Single Table Inheritance
        3. Using Class Table Inheritance
      2. Getting started with events
        1. Lifecycle callbacks
        2. Knowing about event listeners and event subscribers
      3. Writing native queries
        1. The NativeQuery class
        2. Doctrine DBAL
      4. Summary
    13. Index

Product information

  • Title: Persistence in PHP with Doctrine ORM
  • Author(s): Kévin Dunglas
  • Release date: December 2013
  • Publisher(s): Packt Publishing
  • ISBN: 9781782164104