<?php // test.php
require 'bootstrap.php';
use \Acme\Doctrine as DoctrineUser;
$newUserName = $_POST['username'];
$user = new DoctrineUser\User;
$user->setName($newUserName);
$entityManager->persist($user);
$entityManager->flush();
echo "Created user with ID " . $user->getId() . "\n";
?>
没有任何内容被回显或插入数据库?我的类/对象正确实例化:
Doctrine\Common\Util\Debug::dump($user);
object(stdClass)[47]
public '__CLASS__' => string 'Acme\Doctrine\User' (length=17)
public 'id' => null
public 'name' => string 'cookie' (length=6)
public 'email' => null
public 'address1' => null
Doctrine\Common\Util\Debug::dump($entityManager);
object(stdClass)[47]
public '__CLASS__' => string 'Doctrine\ORM\EntityManager' (length=26)
public 'config' =>
object(stdClass)[58]
public '__CLASS__' => string 'Doctrine\ORM\Configuration' (length=26)
public '_attributes' => string 'Array(10)' (length=9)
public 'conn' =>
object(stdClass)[60]
public '__CLASS__' => string 'Doctrine\DBAL\Connection' (length=24)
public '_conn' => string 'Doctrine\DBAL\Driver\PDOConnection' (length=34)
...
目录结构:
/test.php
/src
/Acme
/Doctrine
/User.php
/composer.json
/bootstrap.php
我的服务器日志没有报告,权限似乎都没问题。有什么想法吗?
继承我的User
实体:
<?php
namespace Acme\Doctrine;
/**
* @Entity(repositoryClass="UserRepository") @Table(name="users")
*/
class User
{
/**
* @Id @GeneratedValue @Column(type="integer")
* @var int
**/
protected $id;
/**
* @Column(type="string")
* @var string
**/
protected $name;
/**
* @Column(type="string")
* @var string
**/
protected $email;
/**
* @Column(type="string")
* @var string
**/
protected $address1;
function getId() {
return $this->id;
}
function getName() {
return $this->name;
}
function getEmail() {
return $this->email;
}
function getAddress1() {
return $this->address1;
}
function setId($id) {
$this->id = $id;
}
function setName($name) {
$this->name = $name;
}
function setEmail($email) {
$this->email = $email;
}
function setAddress1($address1) {
$this->address1 = $address1;
}
}
以上内容位于/src/Acme/Doctrine