www.it-ebooks.info
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Frontend Development<br />
$this->setEventLocation($data['event_location']);<br />
}else{<br />
throw new Exception("Error Processing Request:<br />
Insufficient Data Provided");<br />
}<br />
} catch (Exception $e){<br />
Mage::logException($e);<br />
}<br />
return $this;<br />
}<br />
This function will help us out by adding the form data into the current instance of<br />
the registry object, which means we need to create one inside our controller. Let's put<br />
the code for our controller together:<br />
The file location is app/code/local/Mdg/Giftregistry/controllers/<br />
IndexController.php. Refer to the following code snippet:<br />
public function newPostAction()<br />
{<br />
try {<br />
$data = $this->getRequest()->getParams();<br />
$registry = Mage::getModel('mdg_giftregistry/ent<strong>it</strong>y');<br />
$customer = Mage::getSingleton('customer/session')-<br />
>getCustomer();<br />
if($this->getRequest()->getPost() && !empty($data)) {<br />
$registry->updateRegistryData($customer, $data);<br />
$registry->save();<br />
$successMessage = Mage::helper('mdg_giftregistry')->__<br />
('Registry Successfully Created');<br />
Mage::getSingleton('core/session')-<br />
>addSuccess($successMessage);<br />
}else{<br />
throw new Exception("Insufficient Data provided");<br />
}<br />
} catch (Mage_Core_Exception $e) {<br />
Mage::getSingleton('core/session')->addError($e-<br />
>getMessage());<br />
$this->_redirect('*/*/');<br />
}<br />
$this->_redirect('*/*/');<br />
}<br />
We have created a very basic controller action that will handle the registry creation<br />
and that will handle most of the possible exceptions.<br />
[ 112 ]<br />
<strong>www</strong>.<strong>it</strong>-<strong>ebooks</strong>.<strong>info</strong>