Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jdanek/doctrine-plugin

Doctrine 2 integration plugin
https://github.com/jdanek/doctrine-plugin

Last synced: 5 days ago
JSON representation

Doctrine 2 integration plugin

Awesome Lists containing this project

README

        

Doctrine plugin
###############

Doctrine 2 integration plugin.

.. contents::

Requirements
************

- PHP 7.2+
- SunLight CMS 8

Usage
*****

See `Doctrine 2 documentation `_.

Entity registration
===================

Entities need to be registered using the `doctrine.map_entities`_ event before they
can be used.

Table names
===========

Table are automatically prefixed with ``db.prefix`` as defined in the global *config.php*.

If no table name is explicitly specified, ``UnderscoreNamingStrategy`` is used to generate one.

Base entity class
=================

An optional base entity class is available. It provides several active record-esque
utility methods.

Static methods
--------------

- ``find($id)`` - try to find an instance by ID
- ``getRepository()`` - get repository for the entity class
- ``getEntityManager()`` - get the entity manager (protected)

Instance methods
----------------

- ``persist()`` - make the entity managed and persistent
- ``save()`` - persist and flush the entity to the database
- ``delete()`` - delete and flush this entity from the database

Example
-------

Entity definition
^^^^^^^^^^^^^^^^^

.. code:: php

name = $name;
}
}

Basic usage
^^^^^^^^^^^

.. code:: php

save();
var_dump($foo->id);

// find existing entities
Foo::find(1); // by ID
Foo::getRepository()->findBy(['name' => 'test']); // using repository

// saving changes
$foo->name = 'new name';
$foo->save();

// deleting entities
$foo->delete();

Accessing the entity manager
============================

.. code:: php

`_
- `XML mapping `_

Doctrine console
================

Doctrine console can be accessed by clicking on the plugin's "Console" action
in "Administration - Plugins".