如何使用sylius资源模型使用sylius admin crud模板

时间:2016-09-26 10:17:08

标签: symfony sylius

我正在使用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进化得很多,与之完全不同。

1 个答案:

答案 0 :(得分:0)

您应该将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:声明放在