Professional Documents
Culture Documents
Conexión Mongo PHP Por Modelo MVC
Conexión Mongo PHP Por Modelo MVC
<?php
class MongoConnection {
private $host;
private $port;
private $dbname;
}
?>
//Modelo
<?php class Model { protected $_connection; protected $_collection;
protected $_documentArray; public function __construct(MongoConnection
$mongoConnection) { // Create a connection to the db $_connection = new
MongoClient($mongoConnection); // Select the collection $_collection =
$_connection->selectCollection($mongoConnection->getDbName(), 'mycollection');
// Get the document array from the collection $_documentArray = $_collection-
>find(); } // Other model methods go here...} ?>
//Vista <?php echo '<table border="1">'; foreach ($_documentArray as $doc)
{ echo '<tr>'; foreach ($doc as $key =>$value){ echo '<td>'.$key.'</td><td>'.
$value.'</td>'; } echo '</tr>';}echo '</table>'; ?>