Author Topic: help with passing to values to a function.  (Read 431 times)

0 Members and 1 Guest are viewing this topic.

Offline misheckTopic starter

  • Irregular
  • Posts: 43
  • Gender: Male
    • View Profile
help with passing to values to a function.
« on: January 05, 2010, 05:30:39 PM »
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->
Code: [Select]
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 ->
Code: [Select]
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 ->
Code: [Select]
$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.

Offline didier8134

  • Irregular
  • Posts: 2
    • View Profile
Re: help with passing to values to a function.
« Reply #1 on: January 11, 2010, 08:37:48 AM »
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!