Skip to main content
Build a REST API that manages users through Doctrine ORM entities. You use Winter Boot for the application runtime and the winter-doctrine package for the EntityManager and transaction manager. Writes run inside programmatic transactions via EmTransactionManager.

Prerequisites

You need PHP 8.5 or later with the pdo_pgsql extension. You also need a PostgreSQL server. The sample config points at localhost:5432, database appdb, user appuser — replace them with your own server. Start PostgreSQL before you run the app:

Project structure

The sample uses this layout:

Install dependencies

Require the framework and the Doctrine package:

Source files

Switch between the source files. Each tab shows the exact file from the sample.
The single entry point. #[EnableTransactionManagement] activates the transaction infrastructure used by the service.

Configuration

Switch between the two config files. application.yml registers the module and the datasource, and create-table.sql creates the table.
The full sample file registers DoctrineModule, marks defaultdb as primary, and points the ORM at the model directory. It keeps only the server, app identity, module, and datasource keys:
Replace the connection details with your own server, and entityPaths with the absolute path of your src/model directory. See Configuration for every application.yml key.

Run the app

Create the table, start the app, then create and read a user. 1. Create the table:
2. Start the application:
3. Create a user:
4. List users:
5. Delete the user:

Next steps

  • Read the Doctrine module for DBAL access, multi-tenant datasources, and #[Transactional] managers.
  • Browse all Libraries when you need Redis, Kafka, S3, or OpenSearch in the same app.