이번 달에 CodeIgniter에서 my_model & my_controller를 사용하여 이번 달에 처음으로 작업했기 때문에 거의 효과가있었습니다.CodeIgniter : 내 upsert 함수가 my_model/my_controller와 작동하지 않습니다.
제대로 작동하는 삽입 기능이있어서 ID가 있으면 업데이트를 추가하려고합니다.
여기 내 코드입니다 :
function upsert_client($client_id = 0)
{
load_model('client_model');
$this->insertMethodJS();
$this->fields['client'] = $this->_prototype_client();
$user_id = get_user_id();
$company_id = get_company_id();
if ($client_id)
{
$this->data['client'] = $this->client_model->get_record($client_id);
}
if (!$this->ion_auth->in_group(GROUP_NAME_MANAGER, $user_id))
{
redirect('members/dashboard');
}
if ($_POST)
{
$this->load->helper('string');
if ($this->_validate_client())
{
$fields = $this->input->post(null , TRUE);
$fields['user_id'] = $user_id;
$fields['company_id'] = $company_id;
$fields['active'] = 1;
if ($client_id)
{
$fields['id'] = $this->client_model->get_record($client_id);
unset($fields['billing']);
$this->client_model->update($client_id, $fields);
}
else
{
unset($fields['billing']);
$this->client_model->insert($fields);
redirect('members/clients/manage_clients');
}
}
}
$this->template->write_view('content',$this->base_path.'/'.build_view_path(__METHOD__), $this->data);
$this->template->render();
}
function _prototype_client()
{
$fields = array();
$fields['id'] = 0;
$fields['name'] = '';
return $fields;
}
그리고 내 client_model에서 :
class Client_model extends MY_Model {
function get_record($client_id)
{
$query = $this->db->select('id')
->where(array('id'=>$client_id))
->get('clients');
return $query->row_array();
}
}
매번 나는 "클라이언트"편집하려고, 그냥 새가 삽입 .. 현재 내가 편집하려고하는 것은 "이름"필드입니다.
내 편집 버튼 :
<td><a href="add_client/<?= $client->id; ?>"><button class="btn btn-inverse" style="float: right;" type="button">Edit</button></a></td>
이 어떤 도움 감사합니다, 감사합니다! 추가 세부 정보가 필요하면 알려주십시오.