コード例 #1
0
ファイル: add_articles.php プロジェクト: doctrine/couchdb-odm
<?php

require_once "bootstrap.php";
$article1 = new Documents\Article();
$article1->setTitle("Who is John Galt?");
$article1->setBody("Find out!");
$article1->addTag("Philosophy");
$article2 = new Documents\Article();
$article2->setTitle("Human Action");
$article2->setBody("Find out!");
$article2->addTag("Philosophy");
$article2->addTag("Economics");
$article3 = new Documents\Article();
$article3->setTitle("Design Patterns");
$article3->setBody("Find out!");
$article3->addTag("Computer Science");
$dm->persist($article1);
$dm->persist($article2);
$dm->persist($article3);
$dm->flush();
$dm->clear();
コード例 #2
0
<?php

require_once "bootstrap.php";
$article = new Documents\Article();
$article->setTitle("Who is John Galt?");
$article->setBody("Find out!");
$article->addTag("Philosophy");
$dm->persist($article);
$dm->flush();
$dm->clear();
$articles = $dm->getRepository('Documents\\Article')->findAll();
foreach ($articles as $article) {
    echo "ID: " . $article->getId() . "\n";
    echo "Title: " . $article->getTitle() . ", " . $article->getCreated()->format('d.m.Y, H:i') . "\n";
    echo "Tags: \n";
    foreach ($article->getTags() as $tag) {
        echo "  - " . $tag->getName() . "\n";
    }
    echo "\n";
}