Sources for file sample.php in version 4.0 Beta 1
Click on a comment to hide it. Click here to show all comments.
/**
* Sample code, make new blog post with comments
*
* Yes, it will be this easy
**/
// Another test
$blogpost = new BlogPost();
$blogpost->add();
// Set stuff about our blog post
$blogpost->title = 'This is my cool blog post.';
$blogpost->body = 'I did something cool today.';
$blogpost->timetsamp = time();
// find the user who posted me
$blogpost->user->find(array('username' => 'burnsie'));
// add some comments
$blogpost->comments->add();
$blogpost->comments->body = 'Thats awesome!';
$blogpost->comments->user->find(array('username' => 'bok'));
$blogpost->comments->add();
$blogpost->comments->body = 'Yeah!';
$blogpost->comments->user->find(array('firstname' => 'John'));
// save the lot
$blogpost->save();
/**
* More sample code, getting the blog post out and display the comments
**/
$blogpost = new BlogPost();
$blogpost->load($blogpost_id);
?>
<h1><?=$blogpost->title?></h1>
<br />
<div><?=$blogpost->body?></div>
<div>Posted by <?=$blogpost->user->firstname?> <?=$blogpost->user->lastname?> at
<?=date($blogpost->timestamp)?></div>
<hr />
<div>Comments:</div>
<?php foreach ($blogpost->comments as $comment): ?>
<div><?=$comment->user->firstname?> says:</div>
<div><?=$comment->body?></div>
<?php endforeach; ?>
