本文介绍了如何在 sylius 资源模型中使用 sylius admin crud 模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Sylius 1.0.0-dev 并创建名为 Trainee

I'm using Sylius 1.0.0-dev and created model called 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

根据文档.不幸的是,我得到的不是 crud 模板:

according to the docs. Unfortunately instead of crud template I get :

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 进化了很多,它与那个完全不同.

I know there is SyliusAdminBundle with crud templates for resources but by the last version I was using (0.18) sylius evolved much it's completely different from that.

推荐答案

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

You should compare your routing.yml code to other resources in the AdminBundle routing files.

这是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: 声明放在

You should probably put the templates: declaration in

这篇关于如何在 sylius 资源模型中使用 sylius admin crud 模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 10:48