2010-12-19 42 views
0

我有一个用户注册表单,我需要插入一个函数来创建客户端到期日期。 1或2年取决于下拉选择。Codeigniter如何添加一年到用户的注册日期

如何在创建用户时将年份值添加到注册日期?

这是我的一个新的用户

function new_member() 
{ 
    $data = array(
     'Last_Name' => $this->input->post('Last_Name'), 
     'First_Name' => $this->input->post('First_Name'), 
     'Salutation' => $this->input->post('Salutation'), 
     'Address' => $this->input->post('Address'), 
     'City' => $this->input->post('City'), 
     'Province' => $this->input->post('Province'), 
     'Postal' => $this->input->post('Postal'), 
     'Email' => $this->input->post('Email'), 
     'Dial_Up' => $this->input->post('Dial_Up'), 
     'Phone_1' => $this->input->post('Phone_1'), 
     'Phone_2' => $this->input->post('Phone_2'), 
     'Language' => $this->input->post('Language'), 
     'Membership_Cat' => $this->input->post('Membership_Cat'), 
     'Special_Member_Cat' => $this->input->post('Special_Member_Cat'), 
     'Membership_Status' => $this->input->post('Membership_Status'), 
     'Date_DNR' => $this->input->post('Date_DNR'), 
     'Gift_Membership' => $this->input->post('Gift_Membership'), 
     'Gift_Giver' => $this->input->post('Gift_Giver'), 
     'Membership_Length' => $this->input->post('Membership_Length'), 
     'Dues_Paid' => $this->input->post('Dues_Paid'), 
     'Donation' => $this->input->post('Donation'), 
     'Payment_Method' => $this->input->post('Payment_Method'), 
     'Date_Received' => $this->input->post('Date_Received'), 
     'Date_Input' => $this->input->post('Date_Input'), 
     'Membership_Date' => $this->input->post('Membership_Date'), 
     'Renew_Letter_1' => $this->input->post('Renew_Letter_1'), 
     'Renew_Letter_2' => $this->input->post('Renew_Letter_2'), 
     'Renew_Letter_3' => $this->input->post('Renew_Letter_3'), 
     'Date_Letter_Sent' => $this->input->post('Date_Letter_Sent'), 
     'Vol_FA' => $this->input->post('Vol_FA'), 
     'Vol_TEL' => $this->input->post('Vol_TEL'), 
     'Vol_CD' => $this->input->post('Vol_CD'), 
     'Vol_SCBA' => $this->input->post('Vol_SCBA'), 
     'Vol_MAIL' => $this->input->post('Vol_MAIL'), 
     'Vol_SML' => $this->input->post('Vol_SML'), 
     'Vol_BODCOM' => $this->input->post('Vol_BODCOM'), 
     'Vol_OTHER' => $this->input->post('Vol_OTHER'), 
     'Member_Since' => $this->input->post('Member_Since'), 
     'Notes' => $this->input->post('Notes'), 
     ); 

    $this->membership_model->add_record($data); 
    $this->load->view('index_view'); 
} 

控制器这是我的模型

function add_record($data) 
{ 
    $this->db->insert('Membership', $data); 
    return; 
} 

任何帮助表示赞赏!

感谢

回答

1

我接受了你的建议并查看了strtotime函数。由于我有2个会员资格,1和2年,我还需要在函数中提出一个变量。刚刚完成测试,这里是

$Membership_Length = $this->input->post('Membership_Length'); 
     if($Membership_Length == "1") 
     { 
      $length = "+1 year"; 
     } 
     else 
     { 
      $length = "+2 years"; 
     } 

    $Expiry_Date1 = $this->input->post('Membership_Date'); 
    $Expiry_Date = strtotime($length , strtotime($Expiry_Date1)); 
    $Expiry_Date = date('Y-m-j', $Expiry_Date); 
    $date_expiry_array = array('Expiry_Date' => $Expiry_Date); 
    $data = array_merge($data, $date_expiry_array); 
0

看看PHP的strtotime()的功能,例如

$expiry = date('yy-mm-dd', strtotime('+1 year')); 
0

与已安装的方式你的数据阵列可以使用这样一个选项:

$date_received = $this->input->post('Date_Received'); 
$date_expiry = strtotime(date("Y-m-d", strtotime($date_received)). " +1 year"; 
$date_expiry_array = array('Date_Received'=>$date_expiry); 
$data = array_merge($data, $date_expiry_array); 

或如果您使用这种方法:

$date_received = $this->input->post('date_received'); 
$data['date_received'] = strtotime(date("Y-m-d", strtotime($date_received)). " +1 year 

“;

如果要测试1年或2年的过期期限,可以添加if语句以测试date_received的值,然后根据该值添加年数。