Package Data | |
---|---|
Maintainer Username: | uedehua |
Maintainer Contact: | mr.sk@qq.com (陈德华) |
Package Create Date: | 2015-07-11 |
Package Last Update: | 2015-07-12 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-19 03:02:18 |
Package Statistics | |
---|---|
Total Downloads: | 0 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
A Doctrine 2 implementation that melts with Laravel 5.1.X.
Begin reading the full documentation here or go to a specific chapter right away.
修改项目的 composer.json
文件,添加 uedehua/laravel5-doctrine
"require": {
"uedehua/laravel5-doctrine": "5.1.*"
}
执行composer更新:
php composer update
添加provider,打开 app/config/app.php
配置文件, 在providers
数组添加一行.
'UeDehua\LaravelDoctrine\Provider\DoctrineOrmProvider'
添加Facade. 打开 app/config/app.php
配置文件, 在aliases
数组添加一行.
'DoctrineOrm' => 'UeDehua\LaravelDoctrine\Facade\DoctrineOrm'
别忘记发布你的配置.
php artisan config:publish uedehua/laravel5-doctrine --path=vendor/uedehua/laravel5-doctrine/config
这个包使用 Laravel5 本身的数据库配置, 通过 Entity Manager facade (or service locator) 与数据库进行交互. 请参阅 Doctrine 2 文档. 下面的小例子展示了如何在它最简单的形式使用Doctrine ORM.
<?php
$user = new User;
$user->setName('Mitchell');
EntityManager::persist($user);
EntityManager::flush();
添加一个用户到数据库.
<?php
use Doctrine\ORM\Mapping AS ORM;
/**
* @ORM\Entity
* @ORM\Table(name="hk_user")
*/
class User
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string")
*/
private $name;
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
}
User实体基于Annotation,更多请参阅官方文档。
This package is licensed under the MIT license.