dqftyn1717 2013-01-03 00:41
浏览 67

如何在codeigniter中使用cookie保存临时数据?

I'am having problem on how and where i would put my codes in codeigniter. I was new in Php/CI and I was having a hard time with mvc form. I want to put my data's (vaccination record brand) in cookies so that i could store it temporary. I have tried to set my cookies and i got blank result but the data's were inserting in my database. I think i have problem with my controller's code.

my controller's code :

function vaccs($id) {
$data['title'] = $this->main_title.' | Vaccination';
$data['jslibraries'] = $this->inc_files->data_tables_scripts();
$data['uid']         = $id;
$data['employee']    = $this->vaccination_model->get_employee($id);
$data['vaccine']    = $this->vaccination_model->get_vaccinationrecord($id,0);
$data['vaccine1']   = $this->vaccination_model->get_vaccinationrecord($id,1); 
$this->load->view('vaccs',$data);

}

my view's code:

<?php
if (isset($_COOKIE['vaccine'])) {
setcookie('vaccine',$vaccine);
foreach ($_COOKIE[$vaccine] as $vaccine){ ?>

<div class="control-group">
<label class="control-label">
<?php echo '&nbsp'.'<a href="javascript:void(0);"  rel="tooltip"    
title="Delete" onclick="delete_vaccination('.$vaccine->vaccination_record_id.');"><i class="icon-minus-sign"></i></a>'.'';?><?php echo $vaccine->vaccination_record_brand;?>

</label>
</div>

Thank you for any help.

  • 写回答

1条回答 默认 最新

  • du8442 2013-08-27 13:55
    关注

    You should first load cookie helper.You can load it into autoload file inside config folder just add cookie in helper like this

    $autoload['helper'] = array('cookie');
    

    then you can set the cookie like this

    <?php
          $name = 'xyz';
          $this->input->set_cookie('cookie_name', $name, 3600*2);
    ?>
    

    then you can get this cookie value by this

    <?php echo $this->input->cookie('cookie_name');?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题