【问题标题】:Mongodb select document using Phalcon php ODMMongodb 使用 Phalcon php ODM 选择文档
【发布时间】:2014-08-23 14:15:13
【问题描述】:

我正在使用 phalcon php 和 Mongo DB 开发一个应用程序。我想从以下文档中选择post_type = 'page'

{
   "_id" : ObjectId("53f896db461584542200002b"),
   "post_con" : {
      "post_date" : "12-05-14",
      "post_title" : "Test",
      "post_content" : "test content",
      "post_category" : "test cat",
      "post_type" : "page",
      "post_status" : "published",
      "post_modified" : "12-05-14"
   },
   "comment_status" : "open",
   "link_code" : "test-page",
   "seo" : {
      "meta_desc" : "test desc",
      "meta_key" : "test key"
   }
}

【问题讨论】:

  • 你试过什么?这似乎是一个基本查询,应该在Phalcon documentation 中介绍。由于post_type是嵌入文档,所以需要使用dot notation引用字段名(如“post_con.post_type”)。
  • 感谢您的帮助。我得到了他的回答

标签: phalcon


【解决方案1】:

对于那些正在搜索相同内容的人,这里是完整的代码。

$post = Posts::find(array(
            'conditions'=>array('post_con.post_type'=>'blog') ));

    $this->view->postlist = $post; 

在视图中,

{% for posts in postlist %}

{{ posts.post_con['post_title'] }}
{{ posts.post_con['post_content'] }} 

{% endfor  %}

这对某人有帮助。

【讨论】:

    猜你喜欢
    • 2017-02-10
    • 2015-10-07
    • 2012-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 2012-02-10
    • 2014-05-23
    相关资源
    最近更新 更多