Example #1
0
 public function __construct()
 {
     parent::__construct();
     $this->addRelation(wOrm::ONE_TO_MANY, array('column' => 'id', 'foreignClass' => 'Commentaire', 'foreignColumn' => 'article_id'));
     $this->addRelation(wOrm::MANY_TO_MANY, array('column' => 'id', 'foreignClass' => 'Tag', 'foreignColumn' => 'id', 'relationClass' => 'ArticleTag'));
 }
Example #2
0
 public function __construct()
 {
     parent::__construct();
 }
Example #3
0
use model\commentaire\Commentaire;
/* Defines the autoload function */
spl_autoload_register(function ($class) {
    $tab = explode('\\', $class);
    $path = implode(DIRECTORY_SEPARATOR, $tab) . '.class.php';
    if (file_exists($path)) {
        include_once $path;
        return true;
    }
    throw new \Exception('Cannot load : ' . $class);
});
try {
    /* Sets the connection */
    $pdo = new wPdo('mysql:host=localhost;dbname=tests_orm', 'root', 'root');
    $db = new wDb($pdo);
    wOrm::setDataSource($db);
    /* Tests */
    echo '<b>Database overview :</b>';
    echo '<br />';
    echo '- ' . Article::count() . ' article(s)';
    echo '<br />';
    echo '- ' . Commentaire::count() . ' commentaire(s)';
    echo '<br />';
    echo '- ' . Tag::count() . ' tag(s)';
    echo '<br />';
    $article = Article::findOne(array('id' => 1));
    echo '<br />';
    echo 'L\'article intitul&eacute; "';
    echo $article->getTitle();
    echo '" comporte ';
    echo $article->getNbCommentaires();