2017 © Pedro Peláez
 

library pimcore-doctrine-library

Byng pimcore doctrine library

image

byng-systems/pimcore-doctrine-library

Byng pimcore doctrine library

  • Friday, December 25, 2015
  • by Asim
  • Repository
  • 5 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Pimcore doctrine plugin

This plugin allows developers to use doctrine orm to manage objects outside of pimcore., (*1)

Usage

Installation

Add the plugin in composer.json, (*2)

"require": {
    "byng-systems/pimcore-doctrine-library": "1.0.0"
}

You will also need to add a post-install script to install the doctrine cli script. If you don't add the following line then you will have to manually copy 'cli-config.php' from inside the plugin folder to your document root., (*3)

"scripts": {
    "post-install-cmd": "Byng\\Pimcore\\Doctrine\\Composer\\CliManager::postInstall",
    "post-update-cmd": "Byng\\Pimcore\\Doctrine\\Composer\\CliManager::postInstall"
}

Setup

Add the following to 'website/var/config/startup.php'. Set the $entityDir to wherever you wish to create your entities., (*4)

$entityDir = PIMCORE_DOCUMENT_ROOT . "/website/lib/Entity";
$setup = new \Byng\Pimcore\Doctrine\Setup([$entityDir]);
$em = $setup->init();

You can store the entity manager reference ($em) in your DI container or Zend_Registry if you wish. You can also retrieve it from the setup class from anywhere in your code base:, (*5)

$em = \Byng\Pimcore\Doctrine\Setup::getEntityManager();

Test

Open a terminal and 'cd' to your document root and run the following command:, (*6)

./vendor/bin/doctrine

You should see a list of all available doctrine commands, (*7)

Example

Create a product entity, (*8)

NB: You'll probably have to add the 'Entity' namespace to your autoloader., (*9)

website/lib/Entity/Product.php, (*10)

<?php
namespace Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="products")
 **/
class Product
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue 
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     */
    protected $name;

    public function getId()
    {
        return $this->id;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setName($name)
    {
        $this->name = $name;
        return $this;
    }
}

Create the products table using the doctrine cli, (*11)

./vendor/bin/doctrine orm:schema-tool:update --force

Create a repository class to handle product entities, (*12)

website/lib/Entity/Repository/ProductRepository.php, (*13)

<?php
namespace Entity\Repository;

use Byng\Pimcore\Doctrine\AbstractRepository;

class ProductRepository extends AbstractRepository
{
    const ENTITY_CLASS = "Entity\\Product";

    /**
     *
     * @return string
     */
    protected function getEntityClass()
    {
        return static::ENTITY_CLASS;
    }
}

Finally we can write code to persist our entity, (*14)

<?php
use Entity\Repository\ProductRepository;
use Byng\Pimcore\Doctrine\Setup;
use Entity\Product;

$product = new Product();
$product->setName("Test");

$repository = new ProductRepository(Setup::getEntityManager());
$repository->save($product);

The Versions

25/12 2015

dev-master

9999999-dev https://github.com/byng-systems/pimcore-doctrine-library

Byng pimcore doctrine library

  Sources   Download

MIT

The Requires

 

plugin library doctrine pimcore byng

25/12 2015

1.0.0

1.0.0.0 https://github.com/byng-systems/pimcore-doctrine-library

Byng pimcore doctrine library

  Sources   Download

MIT

The Requires

 

plugin library doctrine pimcore byng