【发布时间】:2015-09-02 11:46:56
【问题描述】:
我有一个表经销商和用户。现在每个用户都由他的经销商映射到一个名为 KEY 的字段,该字段唯一地定义了经销商!现在我有一个表单,我可以在其中编辑用户。在这里,如果经销商将用户余额设置为是,那么我想从经销商的余额字段中减去 5 欧元。以下是我的代码:
控制器检查经销商是否已将余额设置为是:
if($this->input->post('balance') === "Yes")
{
$this->reseller_m->deduct();
}
从经销商余额中减去 5 的 Mode 函数:
public function deduct($balance)
{
$this->db->set('balance', 'balance-5');
$this->db->where('id' , $id);
$this->db->update('reseller',$data);
}
编辑代码:
public function edit ($id = NULL)
{
$usertype=$this->session->userdata('usertype');
if($usertype ==="reseller")
{
// Fetch a user or set a new one
if ($id) {
$this->data['user'] = $this->user_m->get($id);
count($this->data['user']) || $this->data['errors'][] = 'User could not be found';
}
else {
$this->data['user'] = $this->user_m->get_new();
}
// Set up the form
$rules = $this->user_m->rules_admin;
$id || $rules['password']['rules'] .= '|required';
$this->form_validation->set_rules($rules);
// Process the form
if ($this->form_validation->run() == TRUE) {
$data = $this->user_m->array_from_post(array('sip_id','sip_pass','name','email', 'password','phone','status','created','balance'));
$data['password'] = $this->user_m->hash($data['password']);
$this->user_m->save($data, $id);
if($this->input->post('balance') === "Yes")
{
$this->reseller_m->deduct();
//echo "goimng";
}
redirect('reseller/user');
}
// Load the view
$this->data['subview'] = 'reseller/user/edit';
$this->load->view('reseller/_layout_main', $this->data);
}
else{
$this->load->view('permission');
}
}
只有当他编辑自己的用户并且不应该影响其他人时,才帮我从经销商那里减去 5。
【问题讨论】:
标签: php codeigniter