I've done both of those things as well as allow ZF to throw exceptions in case of any error. Here is the code that I linked:
/application/usr/models/Controller.php
<?php
/**
* @author C. Fitzpatrick
* @copyright 2009
*/
class Controller extends Zend_Controller_Action
{
public function init()
{
// Instantiate various objects
$this->session->info = new Zend_Session_Namespace('info');
$this->users = new Users;
$this->messages = new Messages;
// Retrieve variables from index
$this->smarty = Zend_Registry::get('smarty');
$this->config = Zend_Registry::get('config');
// Assign variables into smarty
$this->smarty->assign('site_name', $this->config->site->name);
$this->smarty->assign('site_url', $this->config->site->url);
$this->smarty->assign('users', $this->users);
$this->smarty->assign('session', $this->session);
// Register permissions if a user is set
if (isset($this->session->info->user_id))
{
$this->permissions = $this->users->returnUsersGroupPermissions($this->session->info->user_id);
// Make sure the class returns the permissions as an array and not null
if (is_array($this->permissions))
{
$this->smarty->assign('permissions', $this->permissions);
}
}
}
}
?>
/application/usr/models/Messages.php
<?php
/**
* @author C. Fitzpatrick
* @copyright 2009
*/
/*
* Messages class handles all of the private message
* functions for the forum
*
* @author C. Fitzpatrick
* @version 1.0
* @access public
*/
class Messages extends Zend_Db_Table_Abstact
{
/*
* @var object
* @access private
*/
private $database;
/*
* void __construct()
*
* Constructor method for the Messages class,
* allows the database to be initialized.
*
* @access public
* @return void
*/
public function __construct()
{
$this->database = Zend_Registry::get('database');
}
/*
* int returnNumNewMessages(int $userId)
*
* Returns the number of new private messages
* that a user has.
*
* @param int $userId
* @access public
* @return $this->database->fetchAll($query)
*/
public function returnNumNewMessages($userId)
{
$query = "SELECT COUNT(*) FROM `messages` WHERE recipient='$userId' && viewed='0'";
return $this->database->fetchAll($query);
}
/*
* bool composeMessage(int $username, int $recipient, string $message)
*
* Composes a message between 2 members, and returns true if sent and
* false if not sent
*
* @param $username
* @param $recipient
* @param $message
* @access public
* @return bool
*/
public function composeMessage($username, $recipient, $message)
{
}
/*
* bool deleteMessage(int $id)
*
* Deletes a message from a users inbox
*
* @param $id
* @access public
* @return bool
*/
public function deleteMessage($id)
{
}
/*
* array returnMessageInformation($id)
*
* Returns message and post information for a
* specific message by id
*
* @param $id
* @access public
* @return array
*/
public function returnMessageInformation($id)
{
$messagesQuery = "SELECT * FROM `messages` WHERE message_id='$id'";
$postQuery = "SELECT * FROM `posts` WHERE section='pm' && tid='$id'";
return array('messageInfo' => $this->database->fetchAll($messagesQuery), 'postInfo' => $this->database->fetchAll($postQuery));
}
}
?>