How to use sylius admin crud templates with sylius resource models

假装没事ソ 提交于 2019-12-13 07:48:27

问题


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;
    }
}

Then I configure it with config.yml:

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

and routing.yml:

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

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).

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.


回答1:


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

This is the product declaration in the routing/product.yml file

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

You should probably put the templates: declaration in



来源:https://stackoverflow.com/questions/39700196/how-to-use-sylius-admin-crud-templates-with-sylius-resource-models

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!