Persistence in PHP with Doctrine ORM


Persistence in PHP with Doctrine ORM
eBook: $17.99
Formats: PDF, PacktLib, ePub and Mobi formats
$15.29
save 15%!
Print + free eBook + free PacktLib access to the book: $47.98    Print cover: $29.99
$29.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Reviews
Support
Sample Chapters
  • Develop a fully functional Doctrine-backed web application
  • Demonstrate aspects of Doctrine using code samples
  • Generate a database schema from your PHP classes

Book Details

Language : English
Paperback : 114 pages [ 235mm x 191mm ]
Release Date : December 2013
ISBN : 1782164103
ISBN 13 : 9781782164104
Author(s) : Kévin Dunglas
Topics and Technologies : All Books, Web Development, Open Source


Table of Contents

Preface
Chapter 1: Getting Started with Doctrine 2
Chapter 2: Entities and Mapping Information
Chapter 3: Associations
Chapter 4: Building Queries
Chapter 5: Going Further
Index
  • Chapter 1: Getting Started with Doctrine 2
    • Prerequisites
    • Understanding the concepts behind Doctrine
    • Creating a project structure
    • Installing Composer
    • Installing Doctrine
    • Bootstrapping the app
    • Using Doctrine's Entity Manager
    • Configuring Doctrine command-line tools
    • Summary
  • Chapter 2: Entities and Mapping Information
    • Creating the Entity class
    • Generating getters and setters
    • Mapping with Doctrine annotations
      • Knowing about the @Entity annotation
      • Understanding the @Table, @Index, and @UniqueConstraint annotations
      • Diving into the @Column annotation
      • Knowing about the @Id and @GeneratedValue annotations
      • Using other annotations
    • Understanding Doctrine Mapping Types
    • Creating the database schema
    • Installing Data fixtures
    • Creating a simple UI
      • Listing posts
      • Creating and editing posts
      • Deleting posts
    • Summary
  • Chapter 3: Associations
    • Getting started with the Doctrine associations
    • Understanding the @ManyToOne and @OneToMany annotations with the comment system
      • Creating the Comment entity class (owning side)
      • Adding the inverse side to the Post entity class
      • Updating the database schema
      • Adding fixtures for the comments
      • Listing and creating comments
      • Updating the index
    • Understanding the @ManyToMany annotation with tags
      • Creating the Tag entity class (inverse side)
      • Updating the Post entity class (owning side)
      • Updating the schema again
      • Creating tag fixtures
      • Managing the tags of a post
    • Summary
  • Chapter 4: Building Queries
    • Understanding DQL
    • Using the entity repositories
      • Creating custom entity repositories
    • Getting started with Query Builder
    • Filtering by tag
    • Counting comments
    • Summary
  • Chapter 5: Going Further
    • Implementing inheritance
      • Using Mapped Superclasses
      • Using Single Table Inheritance
      • Using Class Table Inheritance
    • Getting started with events
      • Lifecycle callbacks
      • Knowing about event listeners and event subscribers
    • Writing native queries
      • The NativeQuery class
      • Doctrine DBAL
    • Summary

Kévin Dunglas

Kévin Dunglas is the co-founder and CEO of La Coopérative des Tilleuls, a French IT company specializing in e-commerce, owned and managed by its workers themselves. He is also a software architect who works for a lot of companies, including Ubisoft and SensioLabs (creator of Symfony), as an external contractor. He contributes to open source software (especially Symfony, JavaScript, and Ubuntu ecosystems) and has been writing a technical blog for more than 10 years.

Code Downloads

Download the code and support files for this book.


Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


Errata

- 4 submitted: last submission 19 May 2014

Errata type: Typo Page no: 62

It is:

php vendor/bin/doctrine.php orm:run-dql "SELECT p.title, c.body
FROM Blog\Entity\Post p JOIN p.comments c WHERE p.id=1"

Should be:


php vendor/bin/doctrine.php orm:run-dql "SELECT p.title, c.body FROM 
Blog\Entity\Post p JOIN Blog\Entity\Comment c WHERE p.id=1"

Errata type: Technical Page no: 23

It is:

nullable : If  false, the value can be  NULL.

Should be:

nullable : If  true, the value can be  NULL.

Errata type: Typo Page no: 94

It is:

php bin/list-comments.php

Should be:

php bin/last-comments.php

Errata type: Technical Page no: 39

Short explanation: Many-To-One associations are the owning side of the association, but they are the inverse of the One-To-Many associations.

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

Persistence in PHP with Doctrine ORM +    Google Apps: Mastering Integration and Customization    =
50% Off
the second eBook
Price for both: €23.15

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Install Doctrine through the Composer dependency manager
  • Configure Doctrine Command Line Tools
  • Learn to manage relations between entities with different association types
  • Create data fixtures, a custom entity repository, and native SQL queries
  • Master the query builder to generate DQL queries
  • Get started with inheritance and lifecycle events

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.

Approach

Persistence in PHP with Doctrine ORM is a concise, fast, and focused guide to build a blog engine with advanced features such as native queries and lifecycle callbacks.

Who this book is for

This book is primarily intended for PHP developers and architects who want to increase their skills in the field of Persistence and ORM to map the data they are working on to objects they are using in programming. Basic knowledge of databases and PDO and working knowledge of PHP namespaces is a prerequisite.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software