2017-02-19 56 views
0

我想要得到的數據至極不同budnle實體: 枝杈在MainBundle:枝條上載從實體數據在不同的束

 {% extends 'MainBundle:eshop:main.html.twig' %} 

    {% set products = getClassVars(Product) %} 

    {% block body %} 


    <div class="container main-container"> 

    <!-- Main component call to action --> 


    <div id="productslider" class="owl-carousel owl-theme"> 

     <?php $em= $this->getDoctrine()->getManager();?> 
     <?php $products= $em 
     ->getRepository('ProductBundle:Product')->findAll(); ?> 
     {% 
     for product in products %} 
      {% if date(product.createdDate)> date('-1days') %} 


       <div class="item"> 
        <div class="product"> 
         <a class="add-fav tooltipHere" data-toggle="tooltip" 
          data-original-title="Add to Wishlist" 
          data-placement="left"> 

          <i class="glyphicon glyphicon-heart"></i> 
         </a> 

         <div class="image"> 
          <div class="quickview"> 
           <a data-toggle="modal" class="btn btn-xs btn-quickview" href="ajax/product.html" 
            data-target="#productSetailsModalAjax">Quick View </a> 
          </div> 
          <a href="{{ asset('app_dev.php/product/')~product.id~"/show" }}"><img 
             class="img-responsive" alt="img" 
             src="{{ asset('bundles/imageproducts/')~ product.imageName }}" 
             height="250" width="200"></a> 

          <div class="promotion"><span class="discount">15% OFF</span></div> 
         </div> 
         <div class="description"> 
          <h4> 
           <a href="{{ asset('app_dev.php/product/')~product.id~"/show" }}">{{ product.libelle }} </a> 
          </h4> 

          <div class="grid-description"> 
           <p>{{ product.libelle }} </p> 
          </div> 
          <div class="list-description"> 
           <p> {{ product.description }}</p> 
          </div> 
          <span class="size">XL/XXL/S </span></div> 
         <div class="price"><span>$25</span></div> 
         <div class="action-control"><a class="btn btn-primary"> <span class="add2cart"><i 
              class="glyphicon glyphicon-shopping-cart"> </i> Add to cart </span> 
          </a></div> 
        </div> 
       </div> 

      {% endif %} 
     {% endfor %} 
    </div> 
</div> 
</div> 
{% endblock %} 

產品實體:

<?php 

namespace ProductBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use Doctrine\ORM\Mapping\JoinColumn; 
use Doctrine\ORM\Mapping\ManyToOne; 
use Doctrine\ORM\Mapping\OneToMany; 
use Symfony\Component\HttpFoundation\File\File; 
use Vich\UploaderBundle\Mapping\Annotation as Vich; 
use ProductBundle\Repository\ProductRepository; 

/** 
* Produit 
*  @ORM\Entity(repositoryClass="\ProductBundle\Repository\ProductRepository") 
    * @Vich\Uploadable 
* @ORM\Table(name="produit") 
    */ 
    class Product 
    { 
    /** 
    * @ORM\GeneratedValue 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    */ 
    private $id; 

未知「 getClassVars「函數。

我應該怎麼做,任何幫助,請。 忽略此:khvjhvljhbvljhbljhbljhbjhbljhbjhbljhb

回答

0

可以使用

$em->createQueryBuilder() 
    ->select('Product')->from('ABCBundle:Product', 'Product') 
    ->leftJoin('XYZBundle:Category', 'Category', 'Category.productID = Product.id') 
    ->getQuery()->getResult(); 
只是

使加入

Product.yml

oneToOne: 
    description: 
     targetEntity: Description 
     mappedBy: product 
     cascade: ["persist", "remove"] 

Description.yml

oneToOne: 
    product: 
     targetEntity: Product 
     mappedBy: description 
     joinColumn: 
      name: product_id 
      referencedColumn: id  

也 如果你已經創建的,它應該很容易返回實體的關係。

+0

我改變在我的用戶控制器,控制器加載產品,其中產品在不同的包,我並不需要任何註釋由於添加了很多 –

0

就像我說這是100%的注意力不集中 的我張貼的答案,如果有人需要它,所以我們有:

MainBundle希望有用戶

ProductBundle希望擁有的產品

<?php 

namespace MainBundle\Controller; 

use ProductBundle\Repository\ProductRepository; 
use ProductBundle\Entity\Product; 

use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Symfony\Component\HttpFoundation\Request; 

/** 
* User controller. 
* 
*/ 
class UserController extends Controller 
{ 

public function indexAction() 
{ 

    $em= $this->getDoctrine()->getManager(); 
    $products= $em->getRepository('ProductBundle:Product')->findAll(); 



    return $this->render('admin/index.html.twig', array(
     'products' => $products, 


    )); 

    }} 
相關問題