Jump to content

help with passing to values to a function.


misheck

Recommended Posts

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.

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.