Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在zf2中使用doctriMemodule\Form\Element\ObjectSelect时,不显示选项标签_Php_Doctrine Orm_Zend Framework2_Zend Form - Fatal编程技术网

Php 在zf2中使用doctriMemodule\Form\Element\ObjectSelect时,不显示选项标签

Php 在zf2中使用doctriMemodule\Form\Element\ObjectSelect时,不显示选项标签,php,doctrine-orm,zend-framework2,zend-form,Php,Doctrine Orm,Zend Framework2,Zend Form,当使用doctrimemodule\Form\Element\ObjectSelect填充选择框时,我面临一个选项标签为空而选项值正确的问题 这是我的实体 namespace Category\Entity; use Doctrine\ORM\Mapping as ORM; /** * A Category entity. * * @ORM\Entity * @ORM\Table(name="categories") * * @property int $id * @prop

当使用
doctrimemodule\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;
    }

}
问题在于这个空下拉列表。它设置正确的选项值,但不设置标签


您没有正确返回“name”属性

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

public function getName() {
    return $this->name;
}
您还需要将此修复程序应用于其他字段