【问题标题】:Propel Collection using column.name rather than column.phpName使用 column.name 而不是 column.phpName 推进 Collection
【发布时间】:2013-11-13 01:04:48
【问题描述】:

我想查询所有人,然后使用列名而不是 phpName 转换为关联数组。我知道在 PHP 代码中,您应该始终使用 phpName,但我正试图优雅地将内容转储到使用蛇形大小写的表单中。感谢您的帮助。

假设我的架构中有这张表:

<table name='person'>
  <column name='id' phpName='Id' /> 
  <column name='first_name' phpName='FirstName' /> 
  <column name='last_name' phpName='LastName' /> 
</table>

我有以下查询:

$people = PersonQuery::create()->find()->toArray();
var_dump($people);

这会给我:

array(1) { [0]=> 
    array(3) { 
        ["Id"]=> int(1) 
        ["FirstName"]=> string("John") 
        ["LastName"]=> string("Doe") 
    } 
} 

但我真的很想要这个:

array(1) { [0]=> 
    array(3) { 
        ["id"]=> int(1) 
        ["first_name"]=> string("John") 
        ["last_name"]=> string("Doe") 
    } 
} 

干杯!

【问题讨论】:

  • 我想这可能更适合推进论坛。

标签: php mysql collections schema propel


【解决方案1】:

怎么样:

$people = PersonQuery::create()->find()->toArray(BasePeer::TYPE_FIELDNAME);
var_dump($people);

在文件 BasePersonPeer 中查找其他选项,包括 translateFieldName($name, $fromType, $toType),这是另一种方式。

【讨论】:

  • 谢谢!很抱歉回复晚了,但感谢您的反馈
猜你喜欢
  • 1970-01-01
  • 2015-12-02
  • 1970-01-01
  • 1970-01-01
  • 2020-04-05
  • 2011-08-23
  • 1970-01-01
  • 1970-01-01
  • 2019-02-28
相关资源
最近更新 更多