当我尝试从实体获取数据时,我在Symfony(2.4.10)中遇到了问题。
实体:
<?php
namespace ApiBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class BackBill
* @package ApiBundle\Entity
* @ORM\Entity(repositoryClass="ApiBundle\Entity\Repository\MainRepository")
* @ORM\Table(name="sc_backoffice_billing")
*/
class BackBill
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $cli_name;
/*
* @ORM\Column(type="string")
*/
protected $cli_domi;
/*
* @ORM\Column(type="string")
*/
protected $cli_cp;
/**
* @ORM\Column(type="string")
*/
protected $cli_cif;
/**
* @ORM\Column(type="string")
*/
protected $ban_name;
/**
* @ORM\Column(type="string")
*/
protected $ban_dom;
/**
* @ORM\Column(type="string")
*/
protected $ban_cp;
/**
* @ORM\Column(type="string")
*/
protected $ban_cc;
/**
* @ORM\Column(type="string")
*/
protected $ban_iban;
/**
* @ORM\Column(type="string")
*/
protected $ban_swift;
/**
* @ORM\Column(type="string")
*/
protected $sc_logo;
/**
* @ORM\Column(type="string")
*/
protected $sc_name;
/**
* @ORM\Column(type="string")
*/
protected $sc_dom;
/*
* @ORM\Column(type="string")
*/
protected $sc_cp;
/*
* @ORM\Column(type="string")
*/
protected $sc_cif;
/*
* @ORM\Column(type="integer")
*/
protected $incr;
public function __construct($values = null)
{
$this->setValues($values);
}
public function setValues($values)
{
$this->id = (isset($values['id']))?$values['id'] : null;
$this->cli_name = (isset($values['cli_name']))?$values['cli_name'] : null;
$this->cli_domi = (isset($values['cli_domi']))?$values['cli_domi'] : null;
$this->cli_cp = (isset($values['cli_cp']))?$values['cli_cp'] : null;
$this->cli_cif = (isset($values['cli_cif']))?$values['cli_cif'] : null;
$this->ban_name = (isset($values['ban_name']))?$values['ban_name'] : null;
$this->ban_dom = (isset($values['ban_dom']))?$values['ban_dom'] : null;
$this->ban_cp = (isset($values['ban_cp']))?$values['ban_cp'] : null;
$this->ban_cc = (isset($values['ban_cc']))?$values['ban_cc'] : null;
$this->ban_iban = (isset($values['ban_iban']))?$values['ban_iban'] : null;
$this->ban_swift = (isset($values['ban_swift']))?$values['ban_swift'] : null;
$this->sc_logo = (isset($values['sc_logo']))?$values['sc_logo'] : null;
$this->sc_name = (isset($values['sc_name']))?$values['sc_name'] : null;
$this->sc_dom = (isset($values['sc_dom']))?$values['sc_dom'] : null;
$this->sc_cp = (isset($values['sc_cp']))?$values['sc_cp'] : null;
$this->sc_cif = (isset($values['sc_cif']))?$values['sc_cif'] : null;
$this->incr = (isset($values['incr']))?$values['incr'] : null;
}
public function updateValues($values)
{
if(isset($values['id'])) $this->id = $values['id'];
if(isset($values['cli_name'])) $this->cli_name = $values['cli_name'];
if(isset($values['cli_domi'])) $this->cli_domi = $values['cli_domi'];
if(isset($values['cli_cp'])) $this->cli_cp = $values['cli_cp'];
if(isset($values['cli_cif'])) $this->cli_cif = $values['cli_cif'];
if(isset($values['ban_name'])) $this->ban_name = $values['ban_name'];
if(isset($values['ban_dom'])) $this->ban_dom = $values['ban_dom'];
if(isset($values['ban_cp'])) $this->ban_cp = $values['ban_cp'];
if(isset($values['ban_cc'])) $this->ban_cc = $values['ban_cc'];
if(isset($values['ban_iban'])) $this->ban_iban = $values['ban_iban'];
if(isset($values['ban_swift'])) $this->ban_swift = $values['ban_swift'];
if(isset($values['sc_logo'])) $this->sc_logo = $values['sc_logo'];
if(isset($values['sc_name'])) $this->sc_name = $values['sc_name'];
if(isset($values['sc_dom'])) $this->sc_dom = $values['sc_dom'];
if(isset($values['sc_cp'])) $this->sc_cp = $values['sc_cp'];
if(isset($values['sc_cif'])) $this->sc_cif = $values['sc_cif'];
if(isset($values['incr'])) $this->incr = $values['incr'];
}
function getId() {
return $this->id;
}
function getCli_name() {
return $this->cli_name;
}
public function getCliDom() {
return $this->cli_domi;
}
function getCli_cp() {
return $this->cli_cp;
}
function getCli_cif() {
return $this->cli_cif;
}
function getBan_name() {
return $this->ban_name;
}
function getBan_dom() {
return $this->ban_dom;
}
function getBan_cp() {
return $this->ban_cp;
}
function getBan_cc() {
return $this->ban_cc;
}
function getBan_iban() {
return $this->ban_iban;
}
function getBan_swift() {
return $this->ban_swift;
}
function getSc_logo() {
return $this->sc_logo;
}
function getSc_name() {
return $this->sc_name;
}
function getSc_dom() {
return $this->sc_dom;
}
function getSc_cp() {
return $this->sc_cp;
}
function getSc_cif() {
return $this->sc_cif;
}
function getIncr() {
return $this->incr;
}
function setId($id) {
$this->id = $id;
}
function setCli_name($cli_name) {
$this->cli_name = $cli_name;
}
public function setCliDom($cli_domi) {
$this->cli_domi = $cli_domi;
}
function setCli_cp($cli_cp) {
$this->cli_cp = $cli_cp;
}
function setCli_cif($cli_cif) {
$this->cli_cif = $cli_cif;
}
function setBan_name($ban_name) {
$this->ban_name = $ban_name;
}
function setBan_dom($ban_dom) {
$this->ban_dom = $ban_dom;
}
function setBan_cp($ban_cp) {
$this->ban_cp = $ban_cp;
}
function setBan_cc($ban_cc) {
$this->ban_cc = $ban_cc;
}
function setBan_iban($ban_iban) {
$this->ban_iban = $ban_iban;
}
function setBan_swift($ban_swift) {
$this->ban_swift = $ban_swift;
}
function setSc_logo($sc_logo) {
$this->sc_logo = $sc_logo;
}
function setSc_name($sc_name) {
$this->sc_name = $sc_name;
}
function setSc_dom($sc_dom) {
$this->sc_dom = $sc_dom;
}
function setSc_cp($sc_cp) {
$this->sc_cp = $sc_cp;
}
function setSc_cif($sc_cif) {
$this->sc_cif = $sc_cif;
}
function setIncr($incr) {
$this->incr = $incr;
}
Getters和Setter创建得非常好,数据库也很好用。
数据库:
CREATE TABLE `sc_backoffice_billing` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cli_name` varchar(255) DEFAULT NULL,
`cli_domi` varchar(255) DEFAULT NULL,
`cli_cp` varchar(255) DEFAULT NULL,
`cli_cif` varchar(255) DEFAULT NULL,
`ban_name` varchar(255) DEFAULT NULL,
`ban_dom` varchar(255) DEFAULT NULL,
`ban_cp` varchar(255) DEFAULT NULL,
`ban_cc` varchar(255) DEFAULT NULL,
`ban_iban` varchar(255) DEFAULT NULL,
`ban_swift` varchar(255) DEFAULT NULL,
`sc_logo` varchar(255) DEFAULT NULL,
`sc_name` varchar(255) DEFAULT NULL,
`sc_dom` varchar(255) DEFAULT NULL,
`sc_cp` varchar(255) DEFAULT NULL,
`sc_cif` varchar(255) DEFAULT NULL,
`incr` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `_UNIQUE` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT DEFAULT CHARSET=utf8;
控制器:
public function configAction(Request $request) {
$em = $this->getDoctrine()->getEntityManager();
$user_repo = $em->getRepository("ApiBundle:BackBill");
$dataBill = $user_repo->find(1);
return $this->render(
'ApiBundle:backoffice:configFact.html.twig',
array(
'billing' => $dataBill,
)
);
}
然后我有控制器为所选实体呈现视图。
但是当它呈现时,来自实体的一些数据发送为null,但在表中它有一个值:
C:\xampp\htdocs\project\vendor\twig\twig\lib\Twig\Extension\Debug.php:56:
object(ApiBundle\Entity\BackBill)[350]
protected 'id' => int 1
protected 'cli_name' => string 'some data' (length=5)
protected 'cli_domi' => null
protected 'cli_cp' => null
protected 'cli_cif' => string 'some data' (length=3)
protected 'ban_name' => string 'some data' (length=3)
protected 'ban_dom' => string 'some data' (length=5)
protected 'ban_cp' => string 'some data' (length=15)
protected 'ban_cc' => string 'some data' (length=3)
protected 'ban_iban' => string 'some data' (length=3)
protected 'ban_swift' => string 'some data' (length=3)
protected 'sc_logo' => string 'some data' (length=3)
protected 'sc_name' => string 'some data' (length=3)
protected 'sc_dom' => string 'some data' (length=3)
protected 'sc_cp' => null
protected 'sc_cif' => null
protected 'incr' => null
我查了一下树枝,但是如果有任何代码错了,那就很敏感。
我不知道如何解决这个问题......
先谢谢
答案 0 :(得分:0)
我发现我做错了......
我只是从头开始创建实体,而且代码只是实体档案中的*。
<?php
namespace ApiBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class BackBill
* @package ApiBundle\Entity
* @ORM\Entity(repositoryClass="ApiBundle\Entity\Repository\MainRepository")
* @ORM\Table(name="sc_backoffice_billing")
*/
class BackBill
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $cli_name;
/**
* @ORM\Column(type="string")
*/
protected $cli_domi;
/**
* @ORM\Column(type="string")
*/
protected $cli_cp;
/**
* @ORM\Column(type="string")
*/
protected $cli_cif;
/**
* @ORM\Column(type="string")
*/
protected $ban_name;
/**
* @ORM\Column(type="string")
*/
protected $ban_dom;
/**
* @ORM\Column(type="string")
*/
protected $ban_cp;
/**
* @ORM\Column(type="string")
*/
protected $ban_cc;
/**
* @ORM\Column(type="string")
*/
protected $ban_iban;
/**
* @ORM\Column(type="string")
*/
protected $ban_swift;
/**
* @ORM\Column(type="string")
*/
protected $sc_logo;
/**
* @ORM\Column(type="string")
*/
protected $sc_name;
/**
* @ORM\Column(type="string")
*/
protected $sc_dom;
/**
* @ORM\Column(type="string")
*/
protected $sc_cp;
/**
* @ORM\Column(type="string")
*/
protected $sc_cif;
/**
* @ORM\Column(type="integer")
*/
protected $incr;
public function __construct($values = null)
{
$this->setValues($values);
}
public function setValues($values)
{
$this->id = (isset($values['id']))?$values['id'] : null;
$this->cli_name = (isset($values['cli_name']))?$values['cli_name'] : null;
$this->cli_domi = (isset($values['cli_domi']))?$values['cli_domi'] : null;
$this->cli_cp = (isset($values['cli_cp']))?$values['cli_cp'] : null;
$this->cli_cif = (isset($values['cli_cif']))?$values['cli_cif'] : null;
$this->ban_name = (isset($values['ban_name']))?$values['ban_name'] : null;
$this->ban_dom = (isset($values['ban_dom']))?$values['ban_dom'] : null;
$this->ban_cp = (isset($values['ban_cp']))?$values['ban_cp'] : null;
$this->ban_cc = (isset($values['ban_cc']))?$values['ban_cc'] : null;
$this->ban_iban = (isset($values['ban_iban']))?$values['ban_iban'] : null;
$this->ban_swift = (isset($values['ban_swift']))?$values['ban_swift'] : null;
$this->sc_logo = (isset($values['sc_logo']))?$values['sc_logo'] : null;
$this->sc_name = (isset($values['sc_name']))?$values['sc_name'] : null;
$this->sc_dom = (isset($values['sc_dom']))?$values['sc_dom'] : null;
$this->sc_cp = (isset($values['sc_cp']))?$values['sc_cp'] : null;
$this->sc_cif = (isset($values['sc_cif']))?$values['sc_cif'] : null;
$this->incr = (isset($values['incr']))?$values['incr'] : null;
}
public function updateValues($values)
{
if(isset($values['id'])) $this->id = $values['id'];
if(isset($values['cli_name'])) $this->cli_name = $values['cli_name'];
if(isset($values['cli_domi'])) $this->cli_domi = $values['cli_domi'];
if(isset($values['cli_cp'])) $this->cli_cp = $values['cli_cp'];
if(isset($values['cli_cif'])) $this->cli_cif = $values['cli_cif'];
if(isset($values['ban_name'])) $this->ban_name = $values['ban_name'];
if(isset($values['ban_dom'])) $this->ban_dom = $values['ban_dom'];
if(isset($values['ban_cp'])) $this->ban_cp = $values['ban_cp'];
if(isset($values['ban_cc'])) $this->ban_cc = $values['ban_cc'];
if(isset($values['ban_iban'])) $this->ban_iban = $values['ban_iban'];
if(isset($values['ban_swift'])) $this->ban_swift = $values['ban_swift'];
if(isset($values['sc_logo'])) $this->sc_logo = $values['sc_logo'];
if(isset($values['sc_name'])) $this->sc_name = $values['sc_name'];
if(isset($values['sc_dom'])) $this->sc_dom = $values['sc_dom'];
if(isset($values['sc_cp'])) $this->sc_cp = $values['sc_cp'];
if(isset($values['sc_cif'])) $this->sc_cif = $values['sc_cif'];
if(isset($values['incr'])) $this->incr = $values['incr'];
}
function getId() {
return $this->id;
}
function getCli_name() {
return $this->cli_name;
}
public function getCliDom() {
return $this->cli_domi;
}
function getCli_cp() {
return $this->cli_cp;
}
function getCli_cif() {
return $this->cli_cif;
}
function getBan_name() {
return $this->ban_name;
}
function getBan_dom() {
return $this->ban_dom;
}
function getBan_cp() {
return $this->ban_cp;
}
function getBan_cc() {
return $this->ban_cc;
}
function getBan_iban() {
return $this->ban_iban;
}
function getBan_swift() {
return $this->ban_swift;
}
function getSc_logo() {
return $this->sc_logo;
}
function getSc_name() {
return $this->sc_name;
}
function getSc_dom() {
return $this->sc_dom;
}
function getSc_cp() {
return $this->sc_cp;
}
function getSc_cif() {
return $this->sc_cif;
}
function getIncr() {
return $this->incr;
}
function setId($id) {
$this->id = $id;
}
function setCli_name($cli_name) {
$this->cli_name = $cli_name;
}
public function setCliDom($cli_domi) {
$this->cli_domi = $cli_domi;
}
function setCli_cp($cli_cp) {
$this->cli_cp = $cli_cp;
}
function setCli_cif($cli_cif) {
$this->cli_cif = $cli_cif;
}
function setBan_name($ban_name) {
$this->ban_name = $ban_name;
}
function setBan_dom($ban_dom) {
$this->ban_dom = $ban_dom;
}
function setBan_cp($ban_cp) {
$this->ban_cp = $ban_cp;
}
function setBan_cc($ban_cc) {
$this->ban_cc = $ban_cc;
}
function setBan_iban($ban_iban) {
$this->ban_iban = $ban_iban;
}
function setBan_swift($ban_swift) {
$this->ban_swift = $ban_swift;
}
function setSc_logo($sc_logo) {
$this->sc_logo = $sc_logo;
}
function setSc_name($sc_name) {
$this->sc_name = $sc_name;
}
function setSc_dom($sc_dom) {
$this->sc_dom = $sc_dom;
}
function setSc_cp($sc_cp) {
$this->sc_cp = $sc_cp;
}
function setSc_cif($sc_cif) {
$this->sc_cif = $sc_cif;
}
function setIncr($incr) {
$this->incr = $incr;
}
在Symfony Entity Creation中注意sintax,问题非常愚蠢......