misheck Posted January 5, 2010 Share Posted January 5, 2010 I am using a codeigniter framework and I need to pass to 2 $_POST variables to a function in my models the function is model function-> function new_todo($content) { $date = date('l js \of F Y h:i:s A'); $data = array( 'my_day' => $date , 'content' => $content , 'author' => 'Misheck' ); $this->db->insert('query7',$data); } So originally I was just retrieving one value but now I need to add another value for the author. So in my controller I had this originally controller -> function add_item() { $content = $this->input->post('content'); $this->todo_model->new_todo($content); redirect(''); } So now I will add another $author = $this->input->post('author'); after the content variable. I will need to change new_todo($content); and convert that data into an array like this alternative solution -> $content = $this->input->post('content'); $author = $this->input->post('author'); $stuff = new array($content, $author) $this->todo_model->new_todo($stuff); I am now not sure on how I will be able to use or retrieve this data in new_todo() function? I am just short of logical thinking and I am new to Php and MVC. Link to comment https://forums.phpfreaks.com/topic/187330-help-with-passing-to-values-to-a-function/ Share on other sites More sharing options...
didier8134 Posted January 11, 2010 Share Posted January 11, 2010 First of all, you don't construct an array with a new keyword. Just $var = array($var1, $var2); Second, if you wish to go the array route, then just extract the array's element using $content[0] and $content[1] (You change change that var name) Lastly, you could always just add another parameter to the function new_todo($content, $author) and then call that function with the same arguments. Hope it makes sense! Link to comment https://forums.phpfreaks.com/topic/187330-help-with-passing-to-values-to-a-function/#findComment-992756 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.