Prado PHP 框架支持 MongoDB 吗?

发布于 2024-11-25 18:47:34 字数 72 浏览 2 评论 0原文

Prado PHP 框架看起来非常有趣,但在深入研究之前,我想知道 MongoDB 是否可以毫无问题地用作 Prado 的数据库?

The Prado PHP Framework looks very interesting, but before I dive in, I am wondering if MongoDB can be used as the database for Prado without any issues?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

久光 2024-12-02 18:47:34

Prado 基于 Apache Tapestry(一个 Java 框架)。 Tapestry 没有 MongoDB 库(除非最近添加)

作为 PHP,Prado 可以与 MongoDB 一起使用,但必须进行一些 PHP 配置,因为 Mongo PHP 驱动程序是第三方库,并且没有针对 MongoDB 的特定 Prado 库。

首先,配置 MongoDB,安装 MongoDB PHP 驱动程序,然后创建一个 Prado 类来与其交互(与 Apache Tapestry 相同)。遇到的问题数量将与您创建的类以及它如何将 Prado 与 MongoDB 联系起来有关。

标准 PHP 代码如下所示:

<?php
try {
  // open connection to MongoDB server
  $conn = new Mongo('localhost');

  // access database
  $db = $conn->test;

  // access collection
  $collection = $db->items;

  // execute query
  // retrieve all documents
  $cursor = $collection->find();

  // iterate through the result set
  // print each document
  echo $cursor->count() . ' document(s) found. <br/>';  
  foreach ($cursor as $obj) {
    echo 'Name: ' . $obj['name'] . '<br/>';
    echo 'Quantity: ' . $obj['quantity'] . '<br/>';
    echo 'Price: ' . $obj['price'] . '<br/>';
    echo '<br/>';
  }

  // disconnect from server
  $conn->close();
} catch (MongoConnectionException $e) {
  die('Error connecting to MongoDB server');
} catch (MongoException $e) {
  die('Error: ' . $e->getMessage());
}
?>

虽然 Prado 看起来是一个很棒的概念,但我建议使用更成熟的框架,例如 Cake、Zend 或 CodeIgniter。此外还有 Morph,这是 PHP 和 MongoDB 的更高级别的抽象:http://code.google .com/p/mongodb-morph

希望这有帮助。

Prado is based on Apache Tapestry, a Java Framework. Tapestry does not have a MongoDB library (unless recently added)

Being PHP, Prado can work with MongoDB, but one must do some PHP configuration since the Mongo PHP Driver is a third-party library and there is no specific Prado library for MongoDB.

First, configure MongoDB, install the MongoDB PHP Driver, then create a Prado class to interact it (the same with Apache Tapestry). The amount of issues encountered will be in regards to the class you create and how well it bridges Prado with MongoDB.

Standard PHP code looks like this:

<?php
try {
  // open connection to MongoDB server
  $conn = new Mongo('localhost');

  // access database
  $db = $conn->test;

  // access collection
  $collection = $db->items;

  // execute query
  // retrieve all documents
  $cursor = $collection->find();

  // iterate through the result set
  // print each document
  echo $cursor->count() . ' document(s) found. <br/>';  
  foreach ($cursor as $obj) {
    echo 'Name: ' . $obj['name'] . '<br/>';
    echo 'Quantity: ' . $obj['quantity'] . '<br/>';
    echo 'Price: ' . $obj['price'] . '<br/>';
    echo '<br/>';
  }

  // disconnect from server
  $conn->close();
} catch (MongoConnectionException $e) {
  die('Error connecting to MongoDB server');
} catch (MongoException $e) {
  die('Error: ' . $e->getMessage());
}
?>

While Prado looks like a great concept, I would recomend using a more established framework such as Cake, Zend, or CodeIgniter. In addition there is Morph, a higher level of abstraction for PHP and MongoDB: http://code.google.com/p/mongodb-morph

Hope this helps.

记忆で 2024-12-02 18:47:34

您还可以使用受 Prado 启发的 Yii 框架

Yii 有一个扩展系统,其中包括 MongoDB 的扩展,请参阅此 列表

You have also the possibility to use the Yii Framework which was highly inspirated from Prado.

Yii has an extension system, wich include an extension for MongoDB, see this list.

万劫不复 2024-12-02 18:47:34

是的,Prado 使用 mongoDB 没有问题,但您必须使用自己的模型库,例如 morph。 Prado 是一个视觉框架,恰好包含模型库,但不需要使用。

  <?php

        class Home extends TPage
        {
            protected function populateData()
            {
                 $conn = new Mongo('localhost');  // normally should be in your setup
                 $db = $conn->test;
                 $collection = $db->blogs;
                 $cursor = $collection->find();

                foreach ($cursor as $obj) {
                         $result[] = $obj;
                          }
                   return $result

            }
            public function onLoad($param)
            {
                if (!$this->IsPostBack)
                {
                    // Populate the Test Drop Down from database values

                    $this->myRepeater->DataSource = $this->ListTest;

                    $this->myRepeater->dataBind();
                }
            }           
        }
        ?>

实际上,如果您直接在 mongo 集合中嵌套数组,则 mongoDB 适合 Prado 控件的工作方式。注意 dataSource=<%# $this->data->comments %> 嵌套数组注释。

  <com:TRepeater ID="test">

    <prop:ItemTemplate>
      <tr>
        <td><%#  $this->data->blogName %> </td>   
           <com:TRepeater ID="test" dataSource=<%#  $this->data->comments %> >

           <prop:ItemTemplate>
              <ul>
               <li><%#  $this->data->commentText%> </li>   

             </ul>
          </prop:ItemTemplate>

          </com:TRepeater>
      </tr>
    </prop:ItemTemplate>

  </com:TRepeater>

也就是说,我认为普拉多对于大型项目来说不是一个好主意。你会发现它不太畅销而且速度很慢。我认为 Prado 是一个很棒的框架,但我的使用有限。

Yes Prado has no problem working with mongoDB, but you must use your own model library such as morph. Prado is a visual framework that happens to have a model library included with it, but not required to be used.

  <?php

        class Home extends TPage
        {
            protected function populateData()
            {
                 $conn = new Mongo('localhost');  // normally should be in your setup
                 $db = $conn->test;
                 $collection = $db->blogs;
                 $cursor = $collection->find();

                foreach ($cursor as $obj) {
                         $result[] = $obj;
                          }
                   return $result

            }
            public function onLoad($param)
            {
                if (!$this->IsPostBack)
                {
                    // Populate the Test Drop Down from database values

                    $this->myRepeater->DataSource = $this->ListTest;

                    $this->myRepeater->dataBind();
                }
            }           
        }
        ?>

Actually mongoDB lends itself to the way Prado controls work if you have nested arrays directly in your mongo collection. Note dataSource=<%# $this->data->comments %> is nesting the array comments.

  <com:TRepeater ID="test">

    <prop:ItemTemplate>
      <tr>
        <td><%#  $this->data->blogName %> </td>   
           <com:TRepeater ID="test" dataSource=<%#  $this->data->comments %> >

           <prop:ItemTemplate>
              <ul>
               <li><%#  $this->data->commentText%> </li>   

             </ul>
          </prop:ItemTemplate>

          </com:TRepeater>
      </tr>
    </prop:ItemTemplate>

  </com:TRepeater>

That said I do not think that Prado is a good idea for large project. You will find it not very salable and slow. I think Prado is a great framework but I has limited usage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文