在Propel中,我可以选择保存后返回的字段()

时间:2011-02-06 21:12:15

标签: php zend-framework orm propel

我创建了一个新的评论对象并将其保存

$comment = new Comment();
$comment->setText('this is a comment');
$comment->setIp($ip);
$comment->save();

当我执行var_dump($comment)时,我发现该对象有很多细节,我不想传递给MVC架构中的视图。这意味着我必须在视图中进行额外的过滤。

那么有没有办法,在save()之后只选择我稍后想要传递给视图的字段?类似这样的代码,因此$ comment对象现在只有text字段

$comment->save();
$comment->select(array('text'));

1 个答案:

答案 0 :(得分:3)

我只是传递对象...但是如果你想在数组中包含列,你可以使用toArray()或getByName()方法。

在ORM对象中只有一些列对我没有意义。

你的问题被标记为Doctrine和Propel - 这个答案适用于Propel。