[英]Phalcon - Custom Model MetaData strategy
I want to create own custom meta-data parser for Phalcon models (as current hasn't annotations for indexes and mapping one column to another parameter). 我想为Phalcon模型创建自己的自定义元数据解析器(因为当前没有索引注释,也没有将一列映射到另一个参数)。 Unfortunately, when I am returning mapping as array: 不幸的是,当我返回映射为数组时:
/**
* @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;
}
As I found, Phalcon\\Mvc\\Model\\MetaData\\Strategy\\Annotations
in that method returns null
. 正如我发现的那样,该方法中的Phalcon\\Mvc\\Model\\MetaData\\Strategy\\Annotations
返回null
。 My result is like array
of ID_IN_TABLE => PARAMETER_NAME
, eg. 我的结果就像ID_IN_TABLE => PARAMETER_NAME
array
,例如。 'referer_id' => 'refererId'
which map field from database with underscore with camel-case field from model. 'referer_id' => 'refererId'
映射数据库中带有下划线的字段和模型中的驼峰式案例字段。 It throws errors Notice: Undefined index: 0
and Notice: Undefined index: 1
when I am trying to use find
, count
or findFirst
method, eg: 当我尝试使用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)
])
What am I doing wrong? 我究竟做错了什么?
Thanks in advance, David. 预先感谢大卫。
The return value of getColumnMaps()
is supposed to look like this: getColumnMaps()
的返回值应该看起来像这样:
array(
0 => $ordered_column_map,
1 => $reverse_column_map
);
where $ordered_column_map
is ID_IN_TABLE => PARAMETER_NAME
amd $reverse_column_map
is array_flip($ordered_column_map)
. 其中$ordered_column_map
是ID_IN_TABLE => PARAMETER_NAME
和$reverse_column_map
是array_flip($ordered_column_map)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.