Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter passing multiple parameters to controller from view?

I have a system that is outputting a number of images, with a A link next to them to set them as the album cover.

I have multiple albums, and in my database have a field called "is_feature" that is set to 1 if the image is the cover, and 0 if it isnt.

I don't know the best way of selecting the image, i originally outputted something like below;

<a href="/admin/set_photo/'.$image_id.'" title="Set this photo as the feature photo">Set</a>

(image_id is the images id obviously), this function would call the model and set all other photos "is_feature" field to 0, and this photos "is_feature" to 1.

The problem is it is wiping all the other album features as well. I almost need to pass to variables in the A link, the first being the id of the image, the second being the id of the album, then my model function can only set "is_feature" to 0 where album_id = the id of the album passed.

Is there anyway to pass two variables like this? Or am i going about this in totally the wrong way?

like image 271
Carl Bembridge Avatar asked Sep 19 '12 23:09

Carl Bembridge


People also ask

How pass multiple parameters from view to controller in CodeIgniter?

you need to set your base url in congig and remove index. php and also mod_rewrite should be on and money_c should be controller name and updatemanual will be function name. if all this is set then paste error message here.

How pass data from controller view in CodeIgniter using Ajax?

click(function(){ var id_thang = $(this). attr('value'); $. ajax({ url: baseUrl+'/Home/getImage', dataType: 'json', type: 'POST', data: {id_thang: id_thang}, }). done(function(result) { console.


1 Answers

You can set the values in the URL as query parameters

<a href="/admin/set_photo?var1=<?= $image_id;?>&var2=<?= $size;?>"
   title="Set this photo as the feature photo"> Set </a>

Which you can retrieve in the controller

$image_id = $this->input->get('var1');
$image_size = $this->input->get('var2');
like image 87
Nishant Jani Avatar answered Oct 06 '22 02:10

Nishant Jani