- Changed sample directory name
[activemongo.git] / samples / blog / App.php
bloba3eb2b5515510d6cec581e9a901a1bbd519a4c7f
1 <?php
2 require "../../ActiveMongo.php";
3 require "Post.php";
4 require "Author.php";
6 ActiveMongo::connect("activemongo_blog");
8 /* This should be done just once */
9 ActiveMongo::install();
11 /* Create a new author
12 * The property country is not defined
13 * as an AuthorModel property, but it will
14 * be saved.
16 $author = new AuthorModel;
17 $author->username = "crodas";
18 $author->name = "Cesar Rodas";
19 $author->country = "PY";
20 $author->save();
22 /* Add one blog post */
23 $post = new PostModel;
24 $post->uri = "/hello-world";
25 $post->title = "Hello World";
26 $post->author = $author;
27 $post->save();
29 /* Add another post */
30 $post = new PostModel;
31 $post->uri = "/yet-another-post";
32 $post->title = "Yet another post";
33 $post->author = $author;
34 /* add one comment */
35 $post->add_comment("testing", "root@foo.com", "testing comment");
36 $post->save();
38 /* add another comment */
39 $post->add_comment("testing", "root@foo.com", "cool post");
40 $post->save();
42 /* Clean up the current the resultset */
43 /* same as $post = null; $post = new Post Model */
44 /* but more efficient */
45 $post->reset();
46 $post->author = $author->getID();
47 foreach ($post->find() as $bp) {
48 var_dump("Author: ".$bp->author_name);
51 $author->name = "cesar d. rodas";
52 $author->save();
54 var_dump("Author profile has been updated");
56 /**
57 * List our blog posts in the correct order
58 * (descending by Timestamp).
60 foreach ($post->listing_page() as $bp) {
61 var_dump(array("Author" => $bp->author_name, "Title"=>$bp->title));
64 /* delete collections */
65 $post->drop();
66 $author->drop();