Staysee
Staysee

Reputation: 1907

CodeIgniter - Passing two variables from view to controller function

I am trying to pass two variables from the view to the controller. One is the $id of a row that I want to delete from the database. This is working. The other is the $filename of an image that I want to remove from the uploads folder at the same time. I get a server error and I am not sure how else to go about doing this. I am sure it is something simple. Any ideas? Thanks.

//view

<input type="button" onClick="location.href = '<?php echo site_url("myfunction/delete/{$row['id']}/{$row['file_name']}"); ?>'" value="Delete" />

//controller

public function delete($id, $file_name) {

    $table_name = $this->table_name;
    delete_files('../uploads/$file_name');

    $this->load->model('delete', 'delete_model');
    $this->delete_model->delete_row($id, $table_name);

    redirect(site_url('site'));
}

Upvotes: 1

Views: 3408

Answers (1)

Sergey Telshevsky
Sergey Telshevsky

Reputation: 12197

Change

delete_files('../uploads/$file_name');

to

delete_files("../uploads/$file_name");

or

delete_files('../uploads/'.$file_name);

Using single quotes does not expand variables to their values:

$x = "onetwo";
$y1 = '$x';
$y2 = "$x";
$y3 = $x;

echo $y1; // $x
echo $y2; // onetwo
echo $y3; // onetwo

Upvotes: 3

Related Questions