SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 110 | Next

James Kennard

"Mastering Joomla! 1.5 Extension and Framework Development"


/**
* Save a Foobar and redirect
*
*/
function save()
{
// get the data to be saved ($_POST hash)
$data = JRequest::get('POST');
// get the model
$model = $this->getModel('Foobar');
// bind the array to the model and save it.
if ($model->save($data))
{
$message = JText::_('Foobar Saved');
}
else
{
$message = JText::_('Foobar Save Failed');
$message .= ' ['.$model->getError().']';
}
$this->setRedirect('index.php?option=com_foobar', $message);
}
This method is relatively generic, which makes the method very resilient to changes
in the component. Making methods relatively generic makes future development
easier and reduces the impact of changes.
We get a copy of the $_POST hash; this assumes that the data will always be
submitted via a POST request. We proceed to get an instance of the relevant model
and attempt to save the data.
Component Design
[ 82 ]
Using $_POST might look like a security issue, but because of the way in which the
save() method is implemented in JModel (using the JTable bind() method), only
the values that we require will be used.


Pages:
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122