【问题标题】:How to use sylius admin crud templates with sylius resource models如何在 sylius 资源模型中使用 sylius admin crud 模板
【发布时间】:2016-09-26 10:17:07
【问题描述】:

我正在使用Sylius 1.0.0-dev 并创建了名为Trainee 的模型

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use SyliusExtensionBundle\Entity\Product;
use SyliusExtensionBundle\Entity\Order;
use Sylius\Component\Resource\Model\ResourceInterface;

/**
 * Trainee
 *
 * @ORM\Table(name="smartbyte_trainee")
 * @ORM\Entity()
 */
class Trainee implements ResourceInterface
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="firstName", type="string", length=255)
     */
    private $firstName;

    /**
     * @var string
     *
     * @ORM\Column(name="secondName", type="string", length=255)
     */
    private $secondName;

    /**
     * @var string
     *
     * @ORM\Column(name="email", type="string", length=255)
     */
    private $email;

    /**
     * @var string
     *
     * @ORM\Column(name="phone", type="string", length=255)
     */
    private $phone;

    /**
     * @var boolean
     *
     * @ORM\Column(name="is_resignated", type="boolean")
     */
    private $isResignated = false;

    /**
     * @var boolean
     *
     * @ORM\Column(name="is_present", type="boolean")
     */
    private $isPresent = false;

    /**
     * @var Product
     * 
     * @ORM\ManyToOne(targetEntity="SyliusExtensionBundle\Entity\Product")
     * @ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="CASCADE")
     */
    private $product;

    /**
     * @var Order
     * 
     * @ORM\ManyToOne(targetEntity="SyliusExtensionBundle\Entity\Order", inversedBy="trainees")
     * @ORM\JoinColumn(name="order_id", referencedColumnName="id", onDelete="CASCADE")
     */
    private $order;


    public function __toString() {
        return $this->firstName.' '.$this->secondName;
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set firstName
     *
     * @param string $firstName
     * @return Trainee
     */
    public function setFirstName($firstName)
    {
        $this->firstName = $firstName;

        return $this;
    }

    /**
     * Get firstName
     *
     * @return string 
     */
    public function getFirstName()
    {
        return $this->firstName;
    }

    /**
     * Set secondName
     *
     * @param string $secondName
     * @return Trainee
     */
    public function setSecondName($secondName)
    {
        $this->secondName = $secondName;

        return $this;
    }

    /**
     * Get secondName
     *
     * @return string 
     */
    public function getSecondName()
    {
        return $this->secondName;
    }

    /**
     * Set email
     *
     * @param string $email
     * @return Trainee
     */
    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

    /**
     * Get email
     *
     * @return string 
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set phone
     *
     * @param string $phone
     * @return Trainee
     */
    public function setPhone($phone)
    {
        $this->phone = $phone;

        return $this;
    }

    /**
     * Get phone
     *
     * @return string 
     */
    public function getPhone()
    {
        return $this->phone;
    }
    /**
     * @var string
     */
    private $condition;


    /**
     * Set isResignated
     *
     * @param boolean $isResignated
     * @return Trainee
     */
    public function setIsResignated($isResignated)
    {
        $this->isResignated = $isResignated;

        return $this;
    }

    /**
     * Get isResignated
     *
     * @return boolean 
     */
    public function getIsResignated()
    {
        return $this->isResignated;
    }

    /**
     * Set condition
     *
     * @param string $condition
     * @return Trainee
     */
    public function setCondition($condition)
    {
        $this->condition = $condition;

        return $this;
    }

    /**
     * Get condition
     *
     * @return string 
     */
    public function getCondition()
    {
        return $this->condition;
    }

    /**
     * Set product
     *
     * @param Product $product
     * @return Trainee
     */
    public function setProduct(Product $product = null)
    {
        $this->product = $product;

        return $this;
    }

    /**
     * Get product
     *
     * @return Product
     */
    public function getProduct()
    {
        return $this->product;
    }

    /**
     * Set order
     *
     * @param Order $order
     * @return Trainee
     */
    public function setOrder(Order $order = null)
    {
        $this->order = $order;

        return $this;
    }

    /**
     * Get order
     *
     * @return Order 
     */
    public function getOrder()
    {
        return $this->order;
    }

    /**
     * Set isPresent
     *
     * @param boolean $isPresent
     * @return Trainee
     */
    public function setIsPresent($isPresent)
    {
        $this->isPresent = $isPresent;

        return $this;
    }

    /**
     * Get isPresent
     *
     * @return boolean 
     */
    public function getIsPresent()
    {
        return $this->isPresent;
    }
}

然后我用config.yml配置它:

sylius_resource:
resources:
    app.trainee:
        classes:
            model: AppBundle\Entity\Trainee
            repository: AppBundle\Repository\TraineeRepository

routing.yml:

app_trainee:
resource: |
    alias: app.trainee
    section: admin
type: sylius.resource
prefix: /admin

根据docs。不幸的是,我得到的不是 crud 模板:

Unable to find template "/index.html.twig" (looked into: /home/krzysztof/Dokumenty/praca/smartbyte/eventmanager2/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form, /home/krzysztof/Dokumenty/praca/smartbyte/eventmanager2/vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views).

我知道 SyliusAdminBundle 带有用于资源的 crud 模板,但到了我使用的上一个版本 (0.18) sylius 发展了很多,它与那个完全不同。

【问题讨论】:

    标签: symfony sylius


    【解决方案1】:

    您应该将您的routing.yml 代码与AdminBundle 路由文件中的其他资源进行比较。

    这是routing/product.yml 文件中的产品声明

    sylius_admin_product:
        resource: |
            alias: sylius.product
            section: admin
            templates: SyliusAdminBundle:Crud
            except: ['show']
            redirect: update
            grid: sylius_admin_product
            permission: true
            vars:
                all:
                    subheader: sylius.ui.manage_your_product_catalog
                    templates:
                        form: SyliusAdminBundle:Product:_form.html.twig
                index:
                    icon: cube
        type: sylius.resource
    

    您应该将templates: 声明放入

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-08
      相关资源
      最近更新 更多