Twig загружает данные от объекта в другой пакет

я хочу получить данные, которые в другом объекте:
Веточка в 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

Решение

как я уже сказал, это 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,));

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

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector