Symfony 在Sonata管理包中使用标记
我在SonatAdminBundle(问题、文章、新闻)中有几个实体,我希望将标记连接到这些实体。我通过与每个实体的标记实体的多对多关系来创建它。但为此,有必要创建几个中间连接表,这很不方便 我找到了一个bundle,它允许使用额外的字段ResourceType指定连接表。这正是我需要的,我在另一个项目中也做过同样的事情 但FPNTagBundle通过单独的TagManager建立通信,在SonataAdmin中不起作用 你给我什么建议?如何执行这项任务 也许不用担心,留下几个单独的连接表?不过,我还是会为其他六个实体添加标签。。。我担心在所有标记的实体中按标记进行搜索将很困难,因为它将在多个表中运行。解决方法正在进行中 我的管理类:Symfony 在Sonata管理包中使用标记,symfony,tags,sonata-admin,Symfony,Tags,Sonata Admin,我在SonatAdminBundle(问题、文章、新闻)中有几个实体,我希望将标记连接到这些实体。我通过与每个实体的标记实体的多对多关系来创建它。但为此,有必要创建几个中间连接表,这很不方便 我找到了一个bundle,它允许使用额外的字段ResourceType指定连接表。这正是我需要的,我在另一个项目中也做过同样的事情 但FPNTagBundle通过单独的TagManager建立通信,在SonataAdmin中不起作用 你给我什么建议?如何执行这项任务 也许不用担心,留下几个单独的连接表?不过
protected function configureFormFields(FormMapper $formMapper)
{
$tags = $this->hasSubject()
? $this->getTagManager()->loadTagging($this->getSubject())
: array();
$formMapper
// other fields
->add('tags', 'entity', array('class'=>'AppBundle:Tag', 'choices' => $tags, 'multiple' => true, 'attr'=>array('style'=>'width: 100%;')))
;
}
以及SonatAdminBundle中的一个—当执行批删除(在列表视图中)时,钩子preRemove/postRemove不会运行。我们需要扩展标准积垢控制器:
namespace App\AppBundle\Controller;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
class CRUDController extends Controller
{
public function batchActionDelete(ProxyQueryInterface $query)
{
if (method_exists($this->admin, 'preRemove')) {
foreach ($query->getQuery()->iterate() as $object) {
$this->admin->preRemove($object[0]);
}
}
$response = parent::batchActionDelete($query);
if (method_exists($this->admin, 'postRemove')) {
foreach ($query->getQuery()->iterate() as $object) {
$this->admin->postRemove($object[0]);
}
}
return $response;
}
}
namespace App\AppBundle\Controller;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
class CRUDController extends Controller
{
public function batchActionDelete(ProxyQueryInterface $query)
{
if (method_exists($this->admin, 'preRemove')) {
foreach ($query->getQuery()->iterate() as $object) {
$this->admin->preRemove($object[0]);
}
}
$response = parent::batchActionDelete($query);
if (method_exists($this->admin, 'postRemove')) {
foreach ($query->getQuery()->iterate() as $object) {
$this->admin->postRemove($object[0]);
}
}
return $response;
}
}