0

I have create a entity "Fact" width "date" attribute.

/**
 * Fact
 *
 * @ORM\Table(name="fact")
 * @ORM\Entity()
 */
class Fact
{
   .....

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="date", type="datetime")
     */
    private $date;

    /**
     * Get date
     *
     * @return \DateTime 
     */
    public function getDate()
    {
        return $this->date;
    }

    ...
}

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('date', 'date')        
    }

Than i create its CRUD interfaces with symfony command (also i use bootstrapSymfonyBundle):

php app/console generate:doctrine:crud --entity=MlatAdminBundle:Fact --format=annotation

So i got this error:

Impossible to access an attribute ("date") on a string variable ("inline") in ... /vendor/braincrafted/bootstrap-bundle/Bc/Bundle/BootstrapBundle/Resources/views/Form/form_div_layout.html.twig at line 189 

I think that the return type of getDate() function is the problem. I casted it in DateTime Object but nothing change.

Abir
  • 63
  • 8

1 Answers1

0
/**
 * @ORM\Column(type="datetime", name="date")
 * @Gedmo\Timestampable(on="create")
 */
private $date;

try to change your code with this. Also add use Gedmo\Mapping\Annotation as Gedmo; in the top of your code. If you don't have gedmo vendor, install it. After install, you can use that code.

david
  • 3,225
  • 9
  • 30
  • 43
  • Thx david, i Have Gedmo and i try it but nothing change, and in my case this attribute must be entered by the customer. – Abir Sep 24 '13 at 09:44
  • I found the problem:, It must be like this: $builder ->add('date', 'datetime', array('input' => 'datetime','widget' => 'single_text')); – Abir Sep 25 '13 at 14:26
  • But i can't be able to change the format of the date.. 'format_date' => 'yyyy/MM-dd HH:mm:ss' don't work.. – Abir Sep 25 '13 at 14:33