当我将FPNTagBundle用于系统标记时,我遇到了这个问题:
当我刷新网页时,这个问题显而易见
使用params执行'INSERT INTO标记(name,slug,created_at,updated_at)VALUES(?,?,?,?)'时发生异常[null,“”,“2017-06-28 17:41: 34“,”2017-06-28 17:41:34“]:
SQLSTATE [23000]:完整性约束违规:1048列“名称”不能为空 500内部服务器错误 - NotNullConstraintViolationException 2个链接的异常:PDOException»PDOException»
代码控制器:
public function createTagsAction()
{
// create your entity
$post = new Post();
$post->setTitle('salah');
$tagManager = $this->get('fpn_tag.tag_manager');
$f = $this->container->get('request')->request->get('data');
// ask the tag manager to create a Tag object
$fooTag = $tagManager->loadOrCreateTag($f);
// assign the foo tag to the post
$tagManager->addTag($fooTag, $post);
$em = $this->getDoctrine()->getEntityManager();
// persist and flush the new post
$em->persist($post);
$em->flush();
// after flushing the post, tell the tag manager to actually save the tags
$tagManager->saveTagging($post);
// ...
// Load tagging ...
$tagManager->loadTagging($post);
$m = "success";
return $this->render('MedBundle:Default:tag.html.twig',array('m' => $m));
}
代码树枝:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>tags</title>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/flick/jquery-ui.css">
<link href="{{ asset('bundles/med/css/jquery.tagit.css') }}" rel="stylesheet" type="text/css">
</head>
<body>
<h3>
{{ m }}
</h3>
<input type="text" id="myTags" placeholder="your tags" >
<br><br> <input type="submit" id="add" value="add article" >
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="{{ asset('bundles/med/js/tag-it.js') }}" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#myTags").tagit();
});
});
$( "#add" ).click(function() {
$ch = $.trim( $("#myTags").val() );
var $leng = $ch.length;
console.log($leng);
$j = 0;
var $_data = $ch;
$.ajax({
type: "POST",
url: "{{path('tag')}}",
data: $_data,
success: function(data) {
console.log("valide");
},
});
});
</script>
</body>
</html>
实体:
post.php中
<?php
namespace test\MedBundle\Entity;
use DoctrineExtensions\Taggable\Taggable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="acme_post")
*/
class Post implements Taggable
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
private $tags;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
* @return Post
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
public function getTags()
{
$this->tags = $this->tags ?: new ArrayCollection();
return $this->tags;
}
public function getTaggableType()
{
return 'acme_tag';
}
public function getTaggableId()
{
return $this->getId();
}
}
Tagging.php:
<?php
namespace test\MedBundle\Entity;
use \FPN\TagBundle\Entity\Tagging as BaseTagging;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\UniqueConstraint;
/**
* test\MedBundle\Entity
*
* @ORM\Table(uniqueConstraints={@UniqueConstraint(name="tagging_idx", columns={"tag_id", "resource_type", "resource_id"})})
* @ORM\Entity
*/
class Tagging extends BaseTagging
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Tag")
* @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
**/
protected $tag;
}
Tag.php:
<?php
namespace test\MedBundle\Entity;
use \FPN\TagBundle\Entity\Tag as BaseTag;
use Doctrine\ORM\Mapping as ORM;
/**
* test\MedBundle\Entity
*
* @ORM\Table()
* @ORM\Entity
*/
class Tag extends BaseTag
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="Tagging", mappedBy="tag", fetch="EAGER")
**/
protected $tagging;
}
请帮我解决这个问题,谢谢