-1

zendframework-2のAnnotationクラスを使用してフォームを作成しています。このクラスでは、注釈を使用して日付フィールドを作成しようとしていますが、フォームに表示されません。アノテーションを使用してvdateフィールド属性を設定する方法を教えてください。

のコードTestEntity.php

<?php

namespace TestAjax\Model;

use Zend\Form\Annotation;


/*
 * @Annotation\Hydrator("Zend\Stdlib\Hydrator\ObjectProperty")
 * @Annotation\Name("TestEntity")
 */
class TestEntity
{


/**
 * @Annotation\Type("Zend\Form\Element\Date")
 * @Annotation\Required({"required":"true" })
 * @Annotation\Filter({"name":"vdate"})
 * @Annotation\Validator({"name":"Between", "options":{"min":"1970-01-01" "max":"2013-12-31"}})                     
 * @Annotation\Options({"label":"Date:"})
 */
public $vdate;

 /**
 * @Annotation\Type("Zend\Form\Element\Text")
 * @Annotation\Required({"required":"true"})
 * @Annotation\Filter({"name":"StripTags"})
 * @Annotation\Validator({"name":"StringLength", "options":{"min":"5"}})
 * @Annotation\Options({"label":"Last Name:"})
 */
public $lastname;

/**
 * @Annotation\Type("Zend\Form\Element\Radio")
 * @Annotation\Required({"required":"true" })
 * @Annotation\Filter({"name":"StripTags"})
 * @Annotation\Options({"label":"Gender:",
 *                      "value_options" : {"1":"Male","2":"Female"}})
 * @Annotation\Validator({"name":"InArray",
 *                        "options":{"haystack":{"1","2"},
 *                              "messages":{"notInArray":"Gender is not valid"}}})
 * @Annotation\Attributes({"value":"1"})
 */
public $gender;

/**
 * @Annotation\Type("Zend\Form\Element\Select")
 * @Annotation\Required({"required":"true" })
 * @Annotation\Filter({"name":"StripTags"})
 * @Annotation\Options({"label":"Class:",
 *                      "value_options" : {"0":"Select a Class","1":"A","2":"B","3":"C"}})
 * @Annotation\Validator({"name":"InArray",
 *                        "options":{"haystack":{"1","2","3"},
 *                              "messages":{"notInArray":"Please Select a Class"}}})
 * @Annotation\Attributes({"value":"0"})
 */
public $class;


/**
 * @Annotation\Type("Zend\Form\Element\Text")
 * @Annotation\Required({"required":"true" })
 * @Annotation\Filter({"name":"StripTags"})
 * @Annotation\Options({"label":"Username:"})
 */
public $username;

/**
 * @Annotation\Type("Zend\Form\Element\Password")
 * @Annotation\Required({"required":"true" })
 * @Annotation\Filter({"name":"StripTags"})
 * @Annotation\Options({"label":"Password:"})
 */
public $password;
/**
 * @Annotation\Type("Zend\Form\Element\Submit")
 * @Annotation\Attributes({"value":"Submit"})
 */
public $submit;
}
4

2 に答える 2

0

教義を使用している場合は、次の方法を試してください。

クラス宣言の前にこれを含めます。

<?php
    namespace Test\Entity; //Test is your module name and Entity is your folder

    use Doctrine\ORM\Mapping as ORM;
    use Zend\Form\Annotation;

    use Doctrine\Common\Collections\ArrayCollection;
    use Doctrine\Common\Collections\Collection;

/**
 * Test
 *
 * @ORM\Table(name="test")
 * @ORM\Entity
 * @Annotation\Name("Test")
 * @Annotation\Hydrator("Zend\Stdlib\Hydrator\ClassMethods")
 * @property int $id
 * @property ............ other variable/column name

class Test //your file name must be Test.php
{

次に、これを日付に追加します

/**
     * @var \DateTime
     *
     * @ORM\Column(name="vdate", type="datetime", nullable=false)
     * @Annotation\Attributes({"type":"datetime","min":"2010-01-01T00:00:00Z","max":"2020-01-01T00:00:00Z","step":"1"})
     * @Annotation\Options({"label":"V Date:", "format":"Y-m-d\TH:iP"})
     */
public $vdate;

これは役立つはずです。

于 2015-09-13T07:16:06.923 に答える
-1

通常のテキスト ボックス フィールド (zend\form\element\text) を使用し、UI に jquery 日付ピッカーを使用します。

于 2013-02-22T08:49:38.060 に答える