Create Doctrine ORM Entity and pagination in Expressive – 005

Channel Avatar
Comment
X
Share
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: https://youtu.be/UpqOew4sNT0
It is part of the playlist: https://www.youtube.com/playlist?listPL6_nF0awZMoMol4RPLf99WIZuoJ3l87oG

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 kit.co: https://kit.co/beachcasts/beachcasts-studio

ERRATA:
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: https://github.com/Beachcasts/doctrine-expressive-example

Associated Links:
https://www.doctrine-project.org/projects/orm.html – Site for Doctrine ORM
https://getexpressive.org/ – Expressive main site
https://getlaminas.org/ – Laminas Project site

Timeline:
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 https://youtu.be/z13glyDnm6s
Behat for beginners functional REST API testing tutorial https://youtu.be/nFNGDhyFrm4
Doctrine ORM one-to-many bi-directional assoc https://youtu.be/4nEdBDxBc1w
PHP Mess Detector static analysis PHP code smells https://youtu.be/8fEfHESrK5E
Doctrine ORM one-to-many self-referencing assoc https://youtu.be/4dHZ6cZooOk
10 reasons to become a consultant https://youtu.be/J7gpMYAKmDM
10 bad things about consulting https://youtu.be/ELE0G3e7h3c
How to get lines of code in PHP https://youtu.be/HpC-Cvxj6oY
Use UUID with Doctrine ORM for DB keys https://youtu.be/SYuLwMwSIpg
Make a Create handler middlware https://youtu.be/FIYh-VIWUko
Automate Hypermedia creation for PHP REST API https://youtu.be/dX6S-pJVUXI
Learn about Hypermedia and how to create it https://youtu.be/aV6ro_JXL_A
Configure Doctrine ORM https://youtu.be/pFvh5ZNhdOQ
Create PHP middlware with Zend Expressive https://youtu.be/26440j7D0BE

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. https://www.tesla.com/referral/tanya21367

I use TubeBuddy to help me manage my YouTube channel. If you’re interested, click the following link to check it out. https://www.tubebuddy.com/beachcasts

Help support Doctrine ORM: https://www.doctrine-project.org/sponsorship.html

#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 *