我目前正在解析我在 zf2 中的实体文件
我有以下用于解析实体的代码:
$classname = get_class($this->object);
$cmf = $this->em->getMetadataFactory();
$class = $cmf->getMetadataFor($classname);
$fields = $class->fieldMappings;
它返回:
array
'id' =>
array
'fieldName' => string 'id' (length=2)
'type' => string 'integer' (length=7)
'length' => null
'precision' => int 0
'scale' => int 0
'nullable' => boolean false
'unique' => boolean false
'id' => boolean true
'columnName' => string 'id' (length=2)
'artist' =>
array
'fieldName' => string 'artist' (length=6)
'type' => string 'string' (length=6)
'length' => null
'precision' => int 0
'scale' => int 0
'nullable' => boolean false
'unique' => boolean false
'columnName' => string 'artist' (length=6)
'title' =>
array
'fieldName' => string 'title' (length=5)
'type' => string 'string' (length=6)
'length' => null
'precision' => int 0
'scale' => int 0
'nullable' => boolean false
'unique' => boolean false
'columnName' => string 'title' (length=5)
我想在我的列中添加一个新类型。例如,用于配置列的是 uploadfield 或 Datepicker :
/**
* @ORM\Column(type="string")
* @type = 'datepicker'
*/
protected $publishdate;
并在类元数据中获取该日期选择器(用于以 zend 形式创建输入元素)
有什么建议吗?
由固定
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reflClass = new \ReflectionClass($classname);
foreach ($reflClass->getProperties() as $property) {
var_dump($reader->getPropertyAnnotations($property));
}
和这个
namespace Admin\Model;
use Doctrine\ORM\Mapping as ORM,
Admin\Scripts AS Scripts,
Doctrine\ORM\Mapping\Annotation as Ano;
/**
* @Annotation
* @Target("PROPERTY")
*/
class sina extends \Doctrine\Common\Annotations\Annotation
{
/** @var string */
public $sina;
}
/**
* A news entity.
*
* @ORM\Entity
* @ORM\Table(name="news")
* @property string $artist
* @property string $title
* @property int $id
*/
class News extends Scripts\BaseObject
{
/**
* @ORM\Id
* @ORM\Column(type="integer");
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
* @Admin\Model\sina(sina="sina")
*/
protected $artist;
/**
* @ORM\Column(type="string")
*/
protected $title;
}