在 Propel 中,我可以选择在 save() 之后返回的字段吗
我创建一个新的注释对象并保存它
$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'));
I create a new comment object and save it
$comment = new Comment();
$comment->setText('this is a comment');
$comment->setIp($ip);
$comment->save();
When I do a var_dump($comment)
, I see that the object has a lot of detail that I don't want to pass to the view in MVC architecture. This means that I have to do extra filtering in the view.
So is there a way, right after save() to select only the fields that I will later want to pass to the view? Something like this code, so that the $comment object now has only the text
field
$comment->save();
$comment->select(array('text'));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是传递对象...但是如果您想在数组中包含列,您可以使用 toArray() 或 getByName() 方法。
ORM 对象中只有某些列对我来说没有意义。
您的问题被标记为 Doctrine 和 Propel - 此答案适用于 Propel。
I'd just pass the object... But if you want to have the columns in array you can either use toArray() or getByName() methods.
Having only some columns in an ORM object doesn't make sense to me.
You have your question tagged as both Doctrine and Propel - this answer is for Propel.