5

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?

3 Answers 3

13

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');
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this is pretty much it! Only im not using query strings. I had no idea you could pass multiple parameters via the url, im a codeigniter newbie and from the documentation i thought it was limited to one argument (ie controller/function/argument) Thanks for pointing me in the right direction, really appreciated it.
5

Uh what? You can pass whatever you need.

$data = array(
               'title' => 'My Title',
               'heading' => 'My Heading',
               'message' => 'My Message'
          );

$this->load->view('blogview', $data);

2 Comments

No, i'm aware you can pass information from the controller to the view via an array, what i wanted to do is pass multiple parameters to a controller, from the view using A link. Sorry my question is worded a bit badly.
The question is passing parameters from view to controller not the controller to view
0

Depending upon data type as string or as array, there are 3 ways of passing data (You can use any of them explained below, BASED upon YOUR REQUIREMENT):

Through View

  //For data you collected through POST method from FORM, collect them as array
        $data=array(
            'employee_name' => $this->input->post('emp_name'),
            'employee_email' => $this->input->post('emp_email'),
            'employee_password' => $this->input->post('emp_password')
             );

$this->load-> view(''mynextpage", $data)

Through Controller

redirect('controller_name/index'.$valueofcustomer);
OR
redirect(base_url()."controller_name/index/".$valueofcustomer);



//then in your 'view', you can access value of customer like this:
$v_o_c = $this->uri->segment(3); 
echo "your value is " .$v_o_c;

Through Session

$data = array(
                'user_name' => $user_name,
                'is_logged_in' => true
            );

$this->session->set_userdata($data); //set the session
redirect('another_controller/index'); 

//then access those in another_controller like this:
$in = $this->session->set_userdata('$data');

Note: Session data will available only for redirect and lost on next page request

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.