Scott Sz
Scott Sz

Reputation: 3998

Does the Prado PHP Framework support MongoDB?

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?

Upvotes: 1

Views: 390

Answers (3)

adrianj98
adrianj98

Reputation: 573

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.

Upvotes: 0

Aur&#233;lien B
Aur&#233;lien B

Reputation: 4640

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.

Upvotes: 1

Todd Moses
Todd Moses

Reputation: 11039

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.

Upvotes: 3

Related Questions