【发布时间】:2014-02-05 12:56:12
【问题描述】:
我想为 Phalcon 模型创建自己的自定义元数据解析器(因为当前没有索引注释并将一列映射到另一个参数)。不幸的是,当我将映射作为数组返回时:
/**
* @param \Phalcon\Mvc\ModelInterface $model
* @param \Phalcon\DiInterface $di
* @return array
*/
public function getColumnMaps($model, $di)
{
$columns = [];
/** @var \Phalcon\Annotations\Reflection $reflection */
$reflection = $di->get('annotations')->get($model);
foreach ($reflection->getPropertiesAnnotations() as $name => $collection) {
if ($collection->has('Column')) {
$columns[$collection->get('Column')->getNamedArgument('column') ?: $name] = $name;
}
}
return $columns;
}
我发现,该方法中的Phalcon\Mvc\Model\MetaData\Strategy\Annotations 返回null。我的结果类似于ID_IN_TABLE => PARAMETER_NAME 的array,例如。 'referer_id' => 'refererId' 将数据库中的字段与模型中的驼峰式字段映射为下划线。当我尝试使用find、count 或findFirst 方法时,它会抛出错误Notice: Undefined index: 0 和Notice: Undefined index: 1,例如:
Users::find([
implode(' AND ', $conditions),
'bind' => $bind,
'limit' => $this->getLimit(),
'offset' => $this->getLimit() * ($this->getPage() - 1)
])
我做错了什么?
提前致谢, 大卫。
【问题讨论】:
标签: php annotations models phalcon