Prev | Current Page 244 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"


Listing 9.4: One-to-many relationship using Zend_Db_Table
class Users extends Zend_Db_Table_Abstract
{
protected $_name = 'users';
protected $_dependentTables = array('Support');
}
class Support extends Zend_Db_Table_Abstract
{
protected $_name = 'support';
protected $_rowClass = 'SupportTicket??™;
protected $_referenceMap = array(
'Support' => array(
'columns' => array('user_id'),
Licensed to Menshu You
Zend Framework in Action (Ch010) Manning Publications Co. 7
'refTableClass' => 'Users',
'refColumns' => array('id')
)
);
}
Linking these two classes fulfills the third requirement of having the current Places user data integrated
with the support tracker. Users will be able to submit support tickets without having to login to a separate
system.
In order to add support tickets the least we are going to need is a submission form and the
functionality to create the entry in the databases. Listing 9.6 reflects these needs with an editAction and
createAction in our SupportController action controller class.
Listing 9.5: Our SupportController class
class SupportController extends Zend_Controller_Action
{
public function editAction() {} A
public function createAction()
{
$filterInt = new Zend_Filter_Int; B
$filterStripTags = new Zend_Filter_StripTags;
$filterFormat = new Zend_Filter;
$filterFormat->addFilter(new Zend_Filter_StripTags)
->addFilter(new Places_Filter_Markdown); C
$support = new Support;
$newSupport = $support->createNew(); D
$newSupport->user_id = Zend_Auth::getInstance() E
->getIdentity()->id;
$newSupport->type = $filterStripTags->filter(
$this->_getParam('type'));
$newSupport->priority = $filterInt->filter(
$this->_getParam('priority'));
$newSupport->status = $filterStripTags->filter(
$this->_getParam('status'));
$newSupport->title = $filterStripTags->filter(
$this->_getParam('title'));
$newSupport->date_created = date('Y-m-d H:i:s');
$newSupport->body = $filterStripTags->filter(
$this->_getParam('body'));
$newSupport->body_formatted = $filterFormat->filter(
$this->_getParam('body'));
$id = $newSupport->save(); F
$this->_forward('form', 'support', null, array('id' => $id)); G
}
}
A The action method for the support ticket submission form
B Instantiating the objects used to filter submitted data
C A custom filter that converts plain text to HTML using Markdown
D Create a new non-database row
E Get the current user id from Zend_Auth
F Calling the save() method here will trigger the email being sent
G Forward to the ticket submission form
The editAction() is empty as it currently doesn??™t require any more than having the view rendered
which is taken care of by the ViewRenderer action helper.


Pages:
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
gadżety reklamowe flaga polski zdrowy sen lalidl posadzki kamienne