承接 byng-systems/pimcore-doctrine-library 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

byng-systems/pimcore-doctrine-library

Composer 安装命令:

composer require byng-systems/pimcore-doctrine-library

包简介

Byng pimcore doctrine library

README 文档

README

This plugin allows developers to use doctrine orm to manage objects outside of pimcore.

Usage

Installation

Add the plugin in composer.json

"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.

"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.

$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:

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

Test

Open a terminal and 'cd' to your document root and run the following command:

./vendor/bin/doctrine

You should see a list of all available doctrine commands

Example

Create a product entity

NB: You'll probably have to add the 'Entity' namespace to your autoloader.

website/lib/Entity/Product.php

<?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

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

Create a repository class to handle product entities

website/lib/Entity/Repository/ProductRepository.php

<?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

<?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);

统计信息

  • 总下载量: 22
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 5
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-12-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固