Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 准备使用条令扩展树更新分层类别的选项_Symfony_Doctrine Orm_Doctrine Extensions - Fatal编程技术网

Symfony 准备使用条令扩展树更新分层类别的选项

Symfony 准备使用条令扩展树更新分层类别的选项,symfony,doctrine-orm,doctrine-extensions,Symfony,Doctrine Orm,Doctrine Extensions,我在一个symfony项目中使用来以分层方式管理类别 不过,我还没有发现如何简单地管理twig中的添加/编辑部分: 我可以使用childrenHierarchy()方法显示html树结构,但我想更进一步,有如下内容: Root - Cat 1 (+) -- Cat 1-1 (+) -- Cat 1-2 (+) - Cat 2 (+) (+)将打开一个显示(类别)文本字段的模式,允许将此元素分支到所选父元素上。 我还没有在文档中看到(如果可能的话,我也不知道)使用此方法childrenH

我在一个symfony项目中使用来以分层方式管理类别

不过,我还没有发现如何简单地管理twig中的添加/编辑部分: 我可以使用
childrenHierarchy()
方法显示html树结构,但我想更进一步,有如下内容:

Root
- Cat 1  (+)
-- Cat 1-1  (+)
-- Cat 1-2  (+)
- Cat 2  (+)
(+)将打开一个显示(类别)文本字段的模式,允许将此元素分支到所选父元素上。

我还没有在文档中看到(如果可能的话,我也不知道)使用此方法
childrenHierarchy()
,选项允许使用额外的html和ajax调用。

我的实体是基本的:

<?php
namespace CPASimUSante\SimupollBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Claroline\CoreBundle\Entity\User;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * Simupoll categories
 *
 * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
 * @ORM\Table(
 *      name="cpasimusante__simupoll_category",
 *      uniqueConstraints={
 *          @ORM\UniqueConstraint(name="category_unique_name_and_user", columns={"user_id", "name"})
 *      }
 * )
 * @DoctrineAssert\UniqueEntity({"name", "user"})
 * @Gedmo\Tree(type="nested")
 */
class Category
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * name of the category
     * @var string $value
     *
     * @ORM\Column(name="name", type="string", length=255, nullable=false)
     */
    private $name;

    /**
     * @Gedmo\TreeLeft
     * @ORM\Column(name="lft", type="integer")
     */
    private $lft;

    /**
     * @Gedmo\TreeLevel
     * @ORM\Column(name="lvl", type="integer")
     */
    private $lvl;

    /**
     * @Gedmo\TreeRight
     * @ORM\Column(name="rgt", type="integer")
     */
    private $rgt;

    /**
     * @Gedmo\TreeRoot
     * @ORM\Column(name="root", type="integer", nullable=true)
     */
    private $root;

    /**
     * @Gedmo\TreeParent
     * @ORM\ManyToOne(
     *     targetEntity="CPASimUSante\SimupollBundle\Entity\Category",
     *     inversedBy="children"
     * )
     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
     */
    protected $parent;

    /**
     * @ORM\ManyToOne(targetEntity="Claroline\CoreBundle\Entity\User")
     */
    private $user;

    /**
     * @ORM\OneToMany(
     *     targetEntity="CPASimUSante\SimupollBundle\Entity\Category",
     *     mappedBy="parent",
     * )
     * @ORM\OrderBy({"lft" = "ASC"})
     */
    protected $children;

    /**
     * propoerty used in hierarchy display, like selectbox
     */
    private $indentedName;

    public function __construct()
    {
        $this->children = new ArrayCollection();
    }

    /**
     * Returns the resource id.
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Sets the resource id.
     * Required by the ResourceController when it creates a fictionnal root
     *
     * @param integer $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    /**
     * Returns the children resource instances.
     *
     * @return \Doctrine\Common\ArrayCollection|Category[]
     */
    public function getChildren()
    {
        return $this->children;
    }

    /**
     * Returns the parent category.
     *
     * @return \CPASimUSante\SimupollBundle\Entity\Category
     */
    public function getParent()
    {
        return $this->parent;
    }

    /**
     * Sets the parent category.
     *
     * @param \CPASimUSante\SimupollBundle\Entity\Category $parent
     */
    public function setParent(\CPASimUSante\SimupollBundle\Entity\Category $parent = null)
    {
        $this->parent = $parent;
    }

    /**
     * Return the lvl value of the resource in the tree.
     *
     * @return integer
     */
    public function getLvl()
    {
        return $this->lvl;
    }

    public function getUser()
    {
        return $this->user;
    }

    public function setUser(User $user)
    {
        $this->user = $user;
    }

    /**
     * allows hierachy display
     * @return string
     */
    public function __toString()
    {
        return $this->getName();
    }

    /**
     * allows hierachy display
     * @return string
     */
    public function getIndentedName()
    {
        return str_repeat("--", $this->lvl) . $this->name;
        //return str_repeat($this->getParent()." > ", $this->lvl) . $this->name;
    }
}

事实上,正是NodeCorator选项允许自定义输出:

$options = array(
    'decorate' => true,
    'rootOpen' => '<ul>',
    'rootClose' => '</ul>',
    'childOpen' => '<li>',
    'childClose' => '</li>',
    'nodeDecorator' => function($node) {
        return $node['name']. '<a href="#" data-id="'.$node['id'].'" class="btn btn-primary category-add-btn">+</a>';
    }
);
{% block section_content %}
    <div class="panel panel-default">
        <div class="panel-body" id="text_content">
            {{ tree |raw }}
        </div>
    </div>
{% endblock %}
$options = array(
    'decorate' => true,
    'rootOpen' => '<ul>',
    'rootClose' => '</ul>',
    'childOpen' => '<li>',
    'childClose' => '</li>',
    'nodeDecorator' => function($node) {
        return $node['name']. '<a href="#" data-id="'.$node['id'].'" class="btn btn-primary category-add-btn">+</a>';
    }
);
$('#treecontainer').on('click', '.category-add-btn', function(){
    //logic to display modal and pass parameter
});