Ensuring POST/GET etc variables are set?
Posted: Fri Oct 31, 2008 1:03 pm
Below is a section of one of my bad controllers. What can I use so I don't have to keep writing something similar to the below every time I wish to call a model which uses user inputted (is that a word?) data... How should I ensure all the necessary POST/GET etc variables are set? It's this sort of thing, and some others, which often result in my controllers becoming way too longgggg.
Thank you in advance if anyone is able to shed some light on this.
S
Code: Select all
$this->newsModel = new newsModel($registry);
$POSTs = array('title', 'userName', 'body');
$inputs = array();
foreach ($POSTs as $key => $var )
{
$inputs[$var] = empty($_POST[$var]) ? '' : $_POST[$var];
}
if ( isset($_POST['addNews']) )
{
if ( $this->newsModel->add($inputs) == true )
{
redirect('news/');
}
}
S