我有一个下拉列表,其中包含实体旁边的实体+图标列表.但是当我提交表单时,我收到了这个错误:
在第38行的src\FLY\BookingsBundle\Resources\views\Post\show.html.twig中呈现模板("通知:数组到字符串转换")期间抛出异常.
CRITICAL - 未捕获的PHP异常Twig_Error_Runtime:"在"C:\ xampp\htdocs\Symfony\src\FLY\BookingsBundle/Resources/views /"中呈现模板("通知:数组到字符串转换")期间抛出异常发布/ show.html.twig"在第38行." 在C:\ xampp\htdocs\Symfony\app\cache\dev\classes.php第4795行.
class Post
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var array
*
* @ORM\Column(name="compagny", type="array")
*/
private $compagny;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set compagny
*
* @param array $compagny
* @return Post
*/
public function setCompagny($compagny)
{
$this->compagny = $compagny;
return $this;
}
/**
* …Run Code Online (Sandbox Code Playgroud) 我试图获取当前user在我的NotificationExtension.php。但是页面加载非常缓慢,并且我也收到此错误:
错误:在null上调用成员函数getUser()
错误消息说不可能获得当前用户,但是我正在登录。
这是我的服务:
notification:
class: Application\Sonata\UserBundle\Twig\NotificationExtension
arguments: ['@doctrine.orm.entity_manager', '@service_container', '@security.context']
tags:
- { name: twig.extension }
Run Code Online (Sandbox Code Playgroud)
NotificationExtension:
<?php
namespace Application\Sonata\UserBundle\Twig;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Twig_Extension;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Core\Security;
class NotificationExtension extends \Twig_Extension
{
protected $container;
protected $em;
public function __construct(EntityManager $em,ContainerInterface $container, SecurityContext $context)
{
$this->container = $container;
$this->em = $em;
$this->doctrine = $container->get('doctrine');
$this->context = $context;
}
public function getGlobals()
{
$user = $this->container->get('security.context')->getToken()->getUser();
return(array(
'unreadMessagesCount' => $this->em->getRepository('ApplicationSonataUserBundle:Notif')->findBy(
array(
'user' …Run Code Online (Sandbox Code Playgroud) 我有一个表Products,实体tva链接到表Tva,实体图像链接到表Media。我在奏鸣曲管理中呈现网站的所有产品。我希望能够从管理中删除产品。
我希望能够删除产品而不删除其外键链接。
但我有这个错误:
SQLSTATE[23000]:完整性约束冲突:1451 无法删除或更新父行:外键约束失败(
fly.post、CONSTRAINTFK_5A8A6C8D4D79775FFOREIGN KEY (tva_id) REFERENCEStva(id))
这是我的实体电视和图像
/**
* @ORM\ManyToOne(targetEntity="FLY\BookingsBundle\Entity\Tva", cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=true)
*/
private $tva;
/**
* @ORM\ManyToOne(targetEntity="FLY\BookingsBundle\Entity\Media", cascade={"persist","remove"})
* @ORM\JoinColumn(nullable=true)
*/
private $image;
Run Code Online (Sandbox Code Playgroud)
我决定将连接列从这个更改为这个, * @ORM\JoinColumn(nullable=true) 它* @ORM\JoinColumn(onDelete="CASCADE") 可以工作,我可以删除该产品,但它也删除外键,我不希望这样,因为我有其他使用相同图像和 tva 的产品。