Create Doctrine ORM Entity and pagination in Expressive – 005

Channel Avatar
Create Doctrine ORM Entity and pagination in Expressive - 005
Create Doctrine ORM Entity and pagination in Expressive – 005
In this tutorial we create a Doctrine ORM Entity in a PHP Project and use to automate Doctrine ORM queries with a Zend Expressive middleware handler using Paginator, to return as JSON. (see shortcuts below to key points) Adam Culp of Beachcasts php videos creates a new Doctrine ORM ready entity, and highlights what is typically found in a PHP Entity.

Later we will be introducing Zend Framework (Laminas Project) components, as well as components from other projects.

Next video in the series:
It is part of the playlist:

Please * LIKE, COMMENT, AND SUBSCRIBE * – and share with others!

Key Topics:
– Create a Doctrine ORM Entity
– Test Entities with Doctrine ORM CLI
– Add createQueryBuilder
– Get records through Paginator
– Hydrate an array from Paginator to pass to JsonResponse

For a nice list of equipment I use in my studio, and to support the channel if you make any purchases (doesn’t cost you a thing), visit my kit at

At 02:54 I create the Entity directory in the module, which was already done from video 4
At 06:45 Though the ID column in the Entity is integer, the DB in the video shows as char(36) instead of int(11), which is wrong at this stage in the app. To prevent errors you will need to change it to int(11) and auto increment.
At 08:03 In PhpStorm, to automatically generate getters/setters use the CodeGenerate menu item. Note, you may also get some errors because the past DB schema contained an is_admin field. You can remove it, or just ignore it.
At 08:41 Fixed DocBlock for ID to int from uuid. (uuid will be introduced if future videos)
At 23:07 The string for the Repository can also be Announcements::class with the Entity being imported with a ‘use’ statement, which is introduced in later videos.
Let me know if you notice anything that should be errata

Code used in this, and in future videos in this series is located at:

Associated Links: – Site for Doctrine ORM – Expressive main site – Laminas Project site

00:00 Video Intro
01:25 Launch terminal in PhpStorm
01:44 Use terminal to launch bash inside Docker container
02:55 Create a new directory with PhpStorm
03:27 Create a PHP class file for entity with PhpStorm
04:40 Create entity class
06:15 Use database panel in PhpStorm to discover fields needed
06:45 Create entity fields and define them in class
08:50 Create getters and setters for fields in the entity
09:50 Explain typehints for function arguments and defining return type declarations for methods
14:10 Define entity locations in configuration (ConfigProvider)
15:55 Use Doctrine CLI to return the info of the ORM and validate entity existence
18:40 Get Doctrine EntityManager from container
20:30 Create a protected field to store EntityManager in handler
21:00 Create contructor to set entityManager with injected EntityManager
22:50 Access Repository from the EntityManager
25:00 Use createQueryBuilder to pass into Paginator
26:15 Create pagination
27:20 Using paginator run query to get the results
28:30 Hydrate an array to pass to JsonResponse

Other Beachcasts PHP tech videos you might find interesting:
Critical programming issues preventing a PHP 7 upgrade
Behat for beginners functional REST API testing tutorial
Doctrine ORM one-to-many bi-directional assoc
PHP Mess Detector static analysis PHP code smells
Doctrine ORM one-to-many self-referencing assoc
10 reasons to become a consultant
10 bad things about consulting
How to get lines of code in PHP
Use UUID with Doctrine ORM for DB keys
Make a Create handler middlware
Automate Hypermedia creation for PHP REST API
Learn about Hypermedia and how to create it
Configure Doctrine ORM
Create PHP middlware with Zend Expressive

Help through referrals:
Thinking of buying a Tesla electric vehicle? Use this referral link to also get six months of free Supercharging for both of us. Thank you.

I use TubeBuddy to help me manage my YouTube channel. If you’re interested, click the following link to check it out.

Help support Doctrine ORM:

#DoctrineORM #ZendExpressive #Beachcasts

Take the opportunity to connect and share this video with your friends and family if you find it useful.

Keywords: beachcasts, adamculp, doctrine orm, doctrine dbal, create a doctrine entity, php ddd, domain driven design, use doctrine entitymanager, doctrine paginator, doctrine orm repositorymanager, php training videos, doctrine pagination usage, php project, doctrine php, php tutorial, doctrine orm php, doctrine orm tutorial, adam culp, zend expressive tutorial, zend expressive api tutorial, laminas, laminas framework, laminas project, php videos, php orm, php, php doctrine

Read Also

Leave a Reply

Your email address will not be published. Required fields are marked *