setup.txt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. Title: Setup
  2. Author: Dariusz Górecki <darek.krk@gmail.com>
  3. ---
  4. In your main configuration file, witch is by default: `protected/config/main.php` config file.
  5. Add the following to the file:
  6. ~~~
  7. [php]
  8. 'import' => array(
  9. // ...
  10. 'ext.YiiMongoDbSuite.*',
  11. ),
  12. 'components' => array(
  13. // ...
  14. 'mongodb' => array(
  15. 'class' => 'EMongoDB',
  16. 'connectionString' => 'mongodb://localhost',
  17. 'dbName' => 'myDatabaseName',
  18. 'fsyncFlag' => false,
  19. 'safeFlag' => false,
  20. 'useCursor' => false,
  21. ),
  22. // ...
  23. ),
  24. ~~~
  25. - `connectionString`: 'localhost' should be changed to the ip or hostname of your host being connected to. For example if connecting
  26. to a server it might be `'connectionString' => 'mongodb://username@xxx.xx.xx.xx'` where xx.xx.xx.xx is the ip (or hostname)
  27. of your webserver or host.
  28. - `dbName`: is the name you want the collections to be stored in. The database name.
  29. - `fsyncFlag` and `safeFlag` - see the [Write Queries Flags Section][advanced.write-flags],
  30. **state of this flags has massive impact on behavior of this extension, PLEASE read the linked chapter!**
  31. - `useCursor` flag see [Use cursor special topic][special#usecursorflag]
  32. - For more info see the [MongoDB connection page on php.net](http://php.net/manual/en/mongo.connecting.php).
  33. That's all you have to do for setup. You can use it very much like the active record.
  34. Short example:
  35. ~~~
  36. [php]
  37. $client = new Client;
  38. $client->first_name='something';
  39. $client->save();
  40. $clients = Client::model->findAll();
  41. ~~~