[英]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. 我有一个输出大量图像的系统,旁边有一个A链接,将它们设置为专辑封面。
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. 我有多个专辑,在我的数据库中有一个名为“is_feature”的字段,如果图像是封面,则设置为1,如果不是,则设置为0。
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. (image_id显然是图像id),此函数将调用模型并将所有其他照片的“is_feature”字段设置为0,并将此照片的“is_feature”设置为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.
我几乎需要传递给A链接中的变量,第一个是图像的id,第二个是相册的id,然后我的模型函数只能将“is_feature”设置为0,其中album_id =相册的id通过。
Is there anyway to pass two variables like this? 无论如何要传递这样的两个变量? Or am i going about this in totally the wrong way?
或者我是以完全错误的方式解决这个问题?
You can set the values in the URL as query parameters 您可以将URL中的值设置为查询参数
<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');
Uh what? 呃什么? You can pass whatever you need.
你可以通过你需要的任何东西。
$data = array(
'title' => 'My Title',
'heading' => 'My Heading',
'message' => 'My Message'
);
$this->load->view('blogview', $data);
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): 根据数据类型为字符串或数组,有3种传递数据的方式(您可以根据您的要求使用下面解释的任何方法):
//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)
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;
$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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.