[英]Symfony2 - Impossible to access an attribute (“date”) on a string variable (“inline”)
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): 比起我用symfony命令创建它的CRUD接口(我也使用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. 我认为getDate()函数的返回类型是问题。 I casted it in DateTime Object but nothing change.
我在DateTime对象中投射了它,但是没有任何变化。
/**
* @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;
还添加
use Gedmo\\Mapping\\Annotation as Gedmo;
in the top of your code. 在代码的顶部。 If you don't have gedmo vendor, install it.
如果您没有gedmo供应商,请安装它。 After install, you can use that code.
安装后,您可以使用该代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.