2016-09-26 1 views
0

Я использую Sylius 1.0.0-dev и создали модель под названием TraineeКак использовать шаблоны sylius админ Crud с моделями sylius ресурсов

<?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. К сожалению, вместо шаблона сырого я получаю:

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 эволюционировал много это совершенно отличается от этого.

ответ

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: декларацию в