Jump to content

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.