<?php
class Alanstormdotcom_Weblog_IndexController extends Mage_Core_Controller_Front_Action {
	public function testModelAction() {
		echo 'Setup!';
	}
	public function createNewPostAction() {
		$blogpost = Mage::getModel('weblog/blogpost');
		$blogpost->setTitle('Code Post!');
		$blogpost->setPost('This post was created from code!');
		$blogpost->save();
		echo 'post created';
	}
	public function deleteFirstPostAction() {
		$blogpost = Mage::getModel('weblog/blogpost');
		$blogpost->load(1);
		$blogpost->delete();
		echo 'post removed';
	}
	public function showAllBlogPostsAction() {
		$posts = Mage::getModel('weblog/blogpost')->getCollection();
		foreach($posts as $blog_post){
			echo '<h3>'.$blog_post->getTitle().'</h3>';
			echo nl2br($blog_post->getPost());
		}
	}
	public function updatePostsAction() {
		$posts = Mage::getModel('weblog/blogpost')->load(2);
		if($posts->getId()){
			$posts->setTitle('Title Changed!');
			$posts->save();
			$this->showAllBlogPostsAction();
		}
	}
}