在CodeIgniter会话中存储具有相同名称的多个输入 [英] Storing multiple inputs with the same name in a CodeIgniter session

查看:110
本文介绍了在CodeIgniter会话中存储具有相同名称的多个输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CodeIgniter论坛发布了此,用尽了论坛搜索引擎



基本上,我有一个输入,设置为<输入类型=textname =goal> 。根据用户的请求,他们可能会添加另一个目标,它会向DOM投放重复的内容。我需要做的是在我的CodeIgniter控制器中获取这些值,并将它们存储在会话变量中。我的控制器目前是这样构造的:

  function goalsAdd(){
$ meeting_title = $ this-& > post('topic');
$ meeting_hours = $ this-> input-> post('hours');
$ meeting_minutes = $ this-> input-> post('minutes');
$ meeting_goals = $ this-> input-> post('goal');
$ meeting_time = $ meeting_hours。 :。 $ meeting_minutes;

$ sessionData = array(
'totaltime'=> $ meeting_time,
'title'=> $ meeting_title,
'goals'=> $ meeting_goals
);

$ this-> session-> set_userdata($ sessionData);
$ this-> load-> view('test',$ sessionData);
}



目前,显然,我的控制器获取每个输入的值,值,只留下最终值的字符串。我需要存储这些,但是,所以我可以打印他们在随后的页面。



我想我想做的是扩展输入类,以便能够调用$ this-> input-> posts('goal')。最后,我将需要存储其他数组到会话值。



< >解决方案

您希望以下列形式使用:

 < input type = textname =goal []> 

然后,您可以通过以下方式获取控制器中的值:

  $ goal = $ this-> input-> post('goal'); 

然后通过以下方式在会话中设置变量:

  $ this-> session-> set_userdata('goal',$ goal) 

如果要再次检索它。通过以下方式实现:

  $ goal = $ this-> session-> userdata('goal'); 

你会有这样的:

  $ goal [0] ='first goal'; 
$ goal [1] ='第二个目标';

请先尝试:)


I've posted this in the CodeIgniter forum and exhausted the forum search engine as well, so apologies if cross-posting is frowned upon.

Essentially, I've got a single input, set up as <input type="text" name="goal">. At a user's request, they may add another goal, which throws a duplicate to the DOM. What I need to do is grab these values in my CodeIgniter controller and store them in a session variable. My controller is currently constructed thusly:

function goalsAdd(){
    $meeting_title = $this->input->post('topic');
    $meeting_hours = $this->input->post('hours');
    $meeting_minutes = $this->input->post('minutes');
    $meeting_goals = $this->input->post('goal');
    $meeting_time = $meeting_hours . ":" . $meeting_minutes;

    $sessionData = array(
        'totaltime' => $meeting_time,
        'title' => $meeting_title,
        'goals' => $meeting_goals
    );

    $this->session->set_userdata($sessionData);
    $this->load->view('test', $sessionData);
}

Currently, obviously, my controller gets the value of each input, writing over previous values in its wake, leaving only a string of the final value. I need to store these, however, so I can print them on a subsequent page.

What I imagine I'd love to do is extend the input class to be able to call $this->input->posts('goal'). Eventually I will need to store other arrays to session values. But I'm totally open to implementation suggestion.

Thanks so much for any help you can give.

解决方案

You'd want to use this in your form:

<input type="text" name="goal[]">

You can then get the values in the Controller via:

$goal = $this->input->post('goal');

And then set the variable in the session via:

$this->session->set_userdata('goal', $goal);

If you want to retrieve it again. do this via:

$goal = $this->session->userdata('goal');

You'll have something like this:

$goal[0] = 'first goal';
$goal[1] = 'second goal';

Please try it first :)

这篇关于在CodeIgniter会话中存储具有相同名称的多个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆