gpt4 book ai didi

php - 没有从 Symfony2 中的实体获取数据

转载 作者:行者123 更新时间:2023-11-30 22:15:58 24 4
gpt4 key购买 nike

当我尝试从实体获取数据时,我在 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 和 Setters 创建得很好,数据库连接也很好。

数据库:

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;

Controller :

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,

)
);

}

然后我有 Controller 呈现所选实体的 View 。

但是当它呈现时,实体中的一些数据发送 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

我检查了 Twig ,但如果其中的任何代码命名错误,它是敏感的。

我不知道如何解决这个...

提前致谢

最佳答案

我发现我做错了什么......

简单地说,我只是从头开始创建实体,并且在该代码中只在实体存档中保留一个 *。

<?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 的语法,这个问题很愚蠢..

关于php - 没有从 Symfony2 中的实体获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38266409/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com