Метки параметров не отображаются при использовании DoctrineModule \ Form \ Element \ ObjectSelect в zf2

Я столкнулся с проблемой, что метки опций пусты, а значения опций верны, когда поле выбора заполнено с помощью DoctrineModule\Form\Element\ObjectSelect,

Вот моя сущность

namespace Category\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* A Category entity.
*
* @ORM\Entity
* @ORM\Table(name="categories")
*
* @property int $id
* @property string $name
* @property string $slug
* @property string $status
*
*/
class Category
{

const ACTIVE = 1;
const INACTIVE = 0;

/**
* @ORM\Id
* @ORM\Column(type="integer");
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;

/**
* @ORM\Column(type="string");
*/
protected $name;

/**
* @ORM\Column(type="string");
*/
protected $slug;

/**
* @ORM\Column(type="integer");
*/
protected $status;

/**
* @ORM\OneToMany(targetEntity="CategoryAttributes\Entity\CategoryAttributes", mappedBy="category", orphanRemoval=true)
*/
protected $attributes;

/*
* Constructor
*/

public function __construct() {
$this->status = self::ACTIVE;
}

public function setId($id) {
$this->id = $id;
}
public function getId() {
$this->id;
}

public function setName($name) {
$this->name = $name;
}
public function getName() {
$this->name;
}

public function setSlug($slug) {
$this->slug = $slug;
}
public function getSlug() {
$this->slug;
}

public function setStatus($status) {
$this->status = $status;
}
public function getStatus() {
$this->status;
}

public function getArrayCopy() {
return get_object_vars($this);
}

public function exchangeArray($data) {
$this->id = (isset($data['id'])) ? $data['id'] : null;
$this->name = (isset($data['name'])) ? $data['name'] : null;
$this->slug = (isset($data['slug'])) ? $data['slug'] : null;
$this->status = (isset($data['status'])) ? $data['status'] : null;
}

public function populate($data) {
$this->id = isset($data['id']) ? $data['id'] : $this->id;
$this->name = isset($data['name']) ? $data['name'] : $this->name;
$this->slug = isset($data['slug']) ? $data['slug'] : $this->slug;
$this->status = isset($data['status']) ? $data['status'] : $this->status;
}

}

Вот мой класс формы

namespace CategoryAttributes\Form;

use DoctrineModule\Persistence\ObjectManagerAwareInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Zend\Form\Form;

class CategoryAttributesForm extends Form implements ObjectManagerAwareInterface
{

protected $objectManager;

public function __construct(ObjectManager $objectManager) {

$this->setObjectManager($objectManager);

parent::__construct('CategoryAttributes');

$this->add(array(
'name' => 'name',
'attributes' => array(
'type' => 'text',
),
'filters' => array(
array('StringTrim')
),
'options' => array(
'required' => true,
'label' => 'Name',
)
));

$this->add(array(
'name' => 'category',
'type' => 'DoctrineModule\Form\Element\ObjectSelect',
'attributes' => array(
),
'filters' => array(
array('StringTrim')
),
'options' => array(
'required' => true,
'label' => 'Category',
'object_manager' => $this->getObjectManager(),
'target_class' => 'Category\Entity\Category',
'property' => 'name',
'empty_option' => '--- select category ---'
)
));
}

public function setObjectManager(ObjectManager $objectManager) {
$this->objectManager = $objectManager;

return $this;
}

public function getObjectManager() {
return $this->objectManager;
}

}

Эта проблема это пустой выпадающий список Он устанавливает правильные значения параметров, но не метки.

введите описание изображения здесь

0

Решение

Вы неправильно возвращаете свое свойство name.

public function getName() {
$this->name;
}

Должно быть

public function getName() {
return $this->name;
}

Вам также нужно будет применить это исправление и к другим полям.

1

Другие решения

Других решений пока нет …

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