Closed denys281 closed 11 years ago
@denys281 sorry for 3 days of silence.. i've had some problems in private life, please paste your entity
@loostro this is not critical.
My first entity:
namespace Webmil\Frontend\PartnerBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* Price
*
* @ORM\Table(name="price_list")
* @ORM\Entity(repositoryClass="Webmil\Frontend\PartnerBundle\Entity\PriceRepository")
* @Vich\Uploadable
*/
class Price
{
use ORMBehaviors\Translatable\Translatable,
ORMBehaviors\Timestampable\Timestampable,
ORMBehaviors\Sluggable\Sluggable
;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* @Assert\File(
* maxSize="10M",
* mimeTypes={"application/x-rar-compressed", "application/octet-stream", "application/zip", "application/octet-stream"}
* )
* @Vich\UploadableField(mapping="catalog", fileNameProperty="price")
*
* @var File $file
*/
public $file;
/**
* @var string
*
* @ORM\Column(name="price", type="string", length=255, nullable=true)
*/
private $price;
/**
* @ORM\ManyToOne(targetEntity="Webmil\Frontend\PartnerBundle\Entity\Partner", inversedBy="price")
* @ORM\JoinColumn(name="partner_id", referencedColumnName="id", nullable=true)
* */
private $partner;
/**
* @ORM\ManyToMany(targetEntity="\Webmil\Frontend\ProductBundle\Entity\Product", mappedBy="price")
*/
private $product;
public function __construct()
{
$this->product = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
* @return Price
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set price
*
* @param string $price
* @return Price
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* @return string
*/
public function getPrice()
{
return $this->price;
}
public function getPartner()
{
return $this->partner;
}
/**
* Set category
*
* @param \Webmil\Frontend\PartnerBundle\Entity\Partner $category
* @return Model
*/
public function setPartner(\Webmil\Frontend\PartnerBundle\Entity\Partner $partner)
{
$this->partner = $partner;
return $this;
}
public function getSluggableFields()
{
return [ 'title'];
}
}
Second entity, where I have double list.
namespace Webmil\Frontend\ProductBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
/**
* Product
*
* @ORM\Table(name="product")
* @ORM\Entity(repositoryClass="Webmil\Frontend\ProductBundle\Entity\ProductRepository")
*/
class Product
{
use ORMBehaviors\Translatable\Translatable,
ORMBehaviors\Timestampable\Timestampable,
ORMBehaviors\Sluggable\Sluggable
;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* @ORM\ManyToOne(targetEntity="Webmil\Frontend\CategoryBundle\Entity\Category", inversedBy="product")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id", nullable=true)
* */
private $category;
/**
* @ORM\ManyToMany(targetEntity="\Webmil\Frontend\PartnerBundle\Entity\Price", inversedBy="product")
* @ORM\JoinTable(name="product_price",
* joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="Cascade")},
* inverseJoinColumns={@ORM\JoinColumn(name="price_id", referencedColumnName="id", onDelete="Cascade")}
* )
*/
private $price;
public function __construct()
{
$this->category = new \Doctrine\Common\Collections\ArrayCollection();
$this->price = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
* @return Product
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set description
*
* @param string $description
* @return Product
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
public function getCategory()
{
return $this->category;
}
/**
* Set category
*
* @param \Webmil\Frontend\CategoryBundle\Entity\Category $category
* @return Model
*/
public function setCategory($category)
{
$this->category = $category;
return $this;
}
public function getSluggableFields()
{
return [ 'title'];
}
public function getPrice()
{
return $this->price;
}
public function setPrice($price)
{
$this->price = $price;
return $this;
}
}
@denys281 to me it looks like you've got the wrong methods
For a Collection field you should have:
protected $prices
$this->getPrices()
$this->addPrice()
$this->removePrice()
But you have:
protected $price
$this->setPrice()
$this->getPrice()
instead, which is probably the cause of your problem.
@loostro thank you, I update entity:
namespace Webmil\Frontend\ProductBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
/**
* Product
*
* @ORM\Table(name="product")
* @ORM\Entity(repositoryClass="Webmil\Frontend\ProductBundle\Entity\ProductRepository")
*/
class Product
{
use ORMBehaviors\Translatable\Translatable,
ORMBehaviors\Timestampable\Timestampable,
ORMBehaviors\Sluggable\Sluggable
;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* @ORM\ManyToOne(targetEntity="Webmil\Frontend\CategoryBundle\Entity\Category", inversedBy="product")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id", nullable=true)
* */
private $category;
/**
* @ORM\ManyToMany(targetEntity="\Webmil\Frontend\PartnerBundle\Entity\Price", inversedBy="product")
* @ORM\JoinTable(name="product_price",
* joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="Cascade")},
* inverseJoinColumns={@ORM\JoinColumn(name="price_id", referencedColumnName="id", onDelete="Cascade")}
* )
*/
private $prices;
public function __construct()
{
$this->category = new \Doctrine\Common\Collections\ArrayCollection();
$this->price = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
* @return Product
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set description
*
* @param string $description
* @return Product
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
public function getCategory()
{
return $this->category;
}
/**
* Set category
*
* @param \Webmil\Frontend\CategoryBundle\Entity\Category $category
* @return Model
*/
public function setCategory($category)
{
$this->category = $category;
return $this;
}
public function getSluggableFields()
{
return [ 'title'];
}
/**
* Add price
*
* @param \Webmil\Frontend\PartnerBundle\Entity\Price $price
* @return Product
*/
public function addPrice(\Webmil\Frontend\PartnerBundle\Entity\Price $price)
{
$this->price[] = $price;
return $this;
}
/**
* Remove price
*
* @param \Webmil\Frontend\PartnerBundle\Entity\Price $price
*/
public function removePrice(\Webmil\Frontend\PartnerBundle\Entity\Price $price)
{
$this->price->removeElement($price);
}
public function getPrices()
{
return $this->prices;
}
}
But it is does not work. Method getPrices
works, I made foreach($this->prices)
and it showed me selected item, but widget does not show me selected items.
@denys281 does the widget load at all? can you show a screenshot? or copy (relevant part) of HTML output?
@loostro My screenshot
<div class="control-group form_field field_double_list_entity field_prices">
<div class="control-group prices">
<label class="control-label" for="edit_product_prices">Прайси</label>
<div class="controls">
<div id="edit_product_prices_widget_container" class="double-list">
<div class="list-unselected dropdown open">
<div class="double-list-label">Не вибраний</div>
<ul id="edit_product_prices_unselected" class="double-list-dropdown dropdown-menu" role="menu" aria-labelledby="dropdownMenu">
<li data-value="1"><a tabindex="-1" href="#"><i class="icon-ok"></i> test price</a></li>
</ul>
</div>
<div class="list-controls">
<div class="double-list-label"> </div>
<div class="double-list-controls">
<div class="btn-group btn-group-vertical">
<button type="button" class="btn btn-large unselect">
<i class="icon-chevron-left icon-large"></i>
</button>
<button type="button" class="btn btn-large select">
<i class="icon-chevron-right icon-large"></i>
</button>
</div>
</div>
</div>
<div class="list-selected dropdown open">
<div class="double-list-label">Вибрані</div>
<ul id="edit_product_prices_selected" class="double-list-dropdown dropdown-menu" role="menu" aria-labelledby="dropdownMenu"></ul>
</div>
<select id="edit_product_prices" name="edit_product[prices]" class="hidden-select">
<option value=""></option><option value="1">test price</option>
</select>
</div>
</div>
</div>
</div>
@denys281 from what I see, everything is OK:
test price
which is not selected<option value="1">test price</option>
(without selected="selected"
attribute)li
tag is rendered in Не вибраний
(unselected list)@denys281 the form type works like that:
multiple
option enabledselected="selected"
(this is how a regular HTML select tag works)selected="selected"
(this is how a regular HTML select tag works)And only this select tag is submitted.
But for nice GUI we have:
ul
list for not selected itemsul
list for selected itemsselected="selected"
from all unselected options in hidden select tag and adds selected="selected"
for all selected options@loostro hm, when in firebug I removed class hidden-select
, I see simple select list, but not multiple.
@denys281 It should be multiple defined here
@loostro yessss. I just add to my config multiple: true
and all works perfect.
prices:
label: Прайси
formType: double_list_entity
addFormOptions:
property: title
multiple: true
It should be added automatically. I need to investigate why it wasn't.
I don't now if this bug, there are no any documentation for double_list so I use it like in old admingenerator.
In db I have many to many so my entity:
second entity
when I set relations through phpmyadmin, it is all ok.
In admingenerator (for product)
And I have cool double list. But it don't show selected item, that I set in phpmyadmin.
When I try set from admin, I get error.
So I add method in product entity (in old forms it works without this method):
But I have other error
And I can't understand what's wrong...Maybe problem in my entity, but I can't catch.