Developers/Entities
Contents
Introduction
PartKeepr uses Doctrine Entities to map PHP objects to the database.
No manual database queries are required - all queries are handled by Doctrine. Custom queries must be written using DQL, the Doctrine Query Language.
Creating new entities and registering it with the REST API
In order to create a new entity, simply create an entity file as per Doctrine documentation. Then you need to register a Dunglas API resource in the app/config/config_partkeepr.yml file:
resource.part_manufacturer: parent: "api.resource" arguments: [ "PartKeepr\\PartBundle\\Entity\\PartManufacturer" ] tags: [ { name: "api.resource" } ] calls: - method: "initNormalizationContext" arguments: [ { groups: [ "default" ] } ] - method: "initDenormalizationContext" arguments: - { groups: [ "default" ] }
ExtJS Model Syncing
The PartKeepr frontend uses ExtJS, a full-stack JavaScript framework. ExtJS allows PartKeepr to operate on entities (called models in ExtJS) and relations. PartKeepr generates the ExtJS Model files for you.
This means that if you create or change any Doctrine Entity, you need to execute the following command:
php app/console generate:extjs:entities
That command extracts all fields and relations from your entity and generates a model file.
Virtual Fields
Sometimes you need to pass fields over the REST API which shouldn't persisted to the database. For that purpose, you can use the @VirtualField annotation on any property:
class MyEntity { /** * @VirtualProperty(type="string") */ protected $myVirtualField; }
The ExtJS entity generator then puts additional fields in the resulting model file.
Frontend Object Handling
In the ExtJS frontend, you can create objects as you usually would in PHP code. You can even create objects with associations and send them to the REST API in one go.