josueeek/doctrine-point-type

为 doctrine 的包点

dev-master 2019-12-26 18:01 UTC

This package is auto-updated.

Last update: 2024-09-27 04:12:21 UTC


README

版本

如何使用

首先,运行 composer install

composer require josueeek/doctrine-point-type

然后,在您的 bootstrap 中添加

use Doctrine\DBAL\Types\Type;

$em = YourEntityManager();

Type::addType('point', 'Josue\PointType');

// in case silex :)
$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('point', 'point');

或者添加到您的 app/config yml 文件中

doctrine:
    dbal:
        types:
            point: Josue\PointType
        default_connection: default
        connections:
            default:
                driver: pdo_mysql
                host: '%database_host%'
                port: '%database_port%'
                dbname: '%database_name%'
                user: '%database_user%'
                password: '%database_password%'
                charset: UTF8
                mapping_types:
                    point: point

仅适用于 symfony 4

在您的控制器中,在命名空间下面调用文件

namespace App\Controller;

use Josue\Point;
use App\Entity\GeoLocation;

在您的实体中创建一个点类型文件

   *  
   * @ORM\Column(name="GeoLocation", type="point")
   */
   private $GeoLocation;
   
   public function getGeoLocation()
   {
       return $this->GeoLocation;
   }
   public function setGeoLocation($GeoLocation)
   {
      $this->GeoLocation = $GeoLocation;
      return $this;
   }

现在您应该配置您的 doctrine.yaml 文件

    dbal:
        types:
            point: Josue\PointType
        mapping_types:
            point: point

现在就享受吧,好好干!!!