1

I have a problem in Symfony (2.4.10) when I try to get data from the Entity.

Entity:

<?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;
}

The Getters and Setters are very well created and the database have good conection.

Database:

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,

        )
    );

}

Then I have the controller that renders the view for the selected entity.

But when it renders, some data from the entity send null, but in the Table it has a value:

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

I checked the twig, but it's sensitive if any code there it's wrong named.

I don't know how to resolve this...

Thanks in Advance

4
  • have you checked that your values are existing in $premRes, so after fetching it from DB but before rendering? Commented Jul 8, 2016 at 13:02
  • I did it @LBA and I have 'nulls' there... Commented Jul 8, 2016 at 13:25
  • so then this cannot be related to twig for sure. and you say, your Object BackBill with id=1 has all value in table sc_backoffice_billing with id=1? Commented Jul 8, 2016 at 13:28
  • Yes @LBA It's setted and applied with id=1 Commented Jul 8, 2016 at 13:46

1 Answer 1

0

I found what I did wrong...

Simply I just created the Entities from scratch and in that code just remains an * in the entity archive.

<?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;
}

Beware with the sintax with Symfony Entity Creation, something the problem is very silly..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.