Doctrine is an advanced PHP library for object-oriented database work. The main purpose and goal of Doctrine is to describe the database schema using data entities and manipulate the data in a fully object-oriented way.
This paradigm is called ORM (Object-relational mapping), which is design-pattern for converting (wrapping) data stored in a relational database into an object that can be used in an object-oriented language. Thus, to understand and use Doctrine, you must know at least the basics of Object-Oriented Programming.
There are many reasons:
The long-held opinion of the author of this article (Jan Barasek) is that Doctrine is the best way to work with a PHP database. It simply has no competition.
Before you start using Doctrine fully, you need to prepare a suitable environment. If you are just starting out with PHP or don't have senior knowledge, the best choice is to install the Nette Framework with the Baraja Doctrine extension package, which automatically integrates full support. First download the package via Composer, then set up the DI Extension and Doctrine will start working automatically.
For Doctrine to work correctly, you need to prepare an empty database (Doctrine can work with an existing project, but for the first steps this is inappropriate as it risks overwriting existing data) and configure the connection. Since Doctrine is not just a database library, but provides an advanced database framework, you need to solve other configuration. Most of the settings are automatically overwritten in that package for Nette, however in the minimum configuration your server must support the APCu Cache
or SQLite3
extensions.
If everything was configured correctly, a new DI service Baraja\Doctrine\EntityManager
will be created in Nette, which you can inject into Presenter:
<?phpnamespace App\FrontModule\Presenters;use Baraja\Doctrine\EntityManager;final class HomepagePresenter extends BasePresenter{#[Inject]public EntityManager $entityManager;}
If you manage to inject the basic EntityManager service, you can start learning and working with Doctrine.
The following chapters are a combination of a Doctrine technology reference guide, years of experience, design patterns, and ready-made solutions. Together we will go through all the basic elements of Doctrine from defining your own entity, to generating a physical database schema, to working with a versioning tool and production deployment.
I have been using Doctrine for a very long time and have solved thousands of cases in it. We will show tips and tricks on how to use Doctrine to optimize database speed and how to design a database appropriately. You can also use Doctrine for an existing project (if you meet certain conditions) and we'll show you how to do it.
This series of articles was created to help my training and consulting students. If you need to discuss or explain certain topics in more detail, you can email me at jan@barasek.com. Because this is a relatively demanding technology, all questions will be treated as a paid consultation.
Jan Barášek Více o autorovi
Autor článku pracuje jako seniorní vývojář a software architekt v Praze. Navrhuje a spravuje velké webové aplikace, které znáte a používáte. Od roku 2009 nabral bohaté zkušenosti, které tímto webem předává dál.
Rád vám pomůžu:
Články píše Jan Barášek © 2009-2024 | Kontakt | Mapa webu
Status | Aktualizováno: ... | en