Как устранить ошибку в методе?
1
получаю ошибку при сохранении данных.
Дебажил атрибуты метода,все приходят, но $id=0, может из-за него я получаю false на проверке.Хотя это не точно, т.к. я не силен в данном фреймворке и если убрать мой добавленный фукнционал,а именно строку: 'marketing_reason_for_leaving_id' => $this->input->post('marketing_reason_for_leaving_id') ? $this->input->post('marketing_reason_for_leaving_id') : null,
то все работает. Как можно исправить?
Может кто поможет исправить...
Контроллер
private function _save()
{
$id = (int)$this->input->post('id');
if(empty($_POST)){ echo'error';}else
// get original customer status so we can determine whether to update
// the subscription active date or not
$original_record = $this->organisation_model->get_by_id($id);
$marketing_optin_date = $this->input->post('marketing_optin_date') ? date("Y-m-d", strtotime(str_replace("/", "-", $this->input->post('marketing_optin_date')))) : null;
$agreement_renewal_date = $this->input->post('agreement_renewal_date') ? date("Y-m-d", strtotime(str_replace("/", "-", $this->input->post('agreement_renewal_date')))) : null;
$postcode_data_id = $this->input->post('postcode_data_id') ? $this->input->post('postcode_data_id') : null;
$postcode_new = $this->input->post('postcode_new') ? $this->input->post('postcode_new') : null;
if(isset($postcode_new) && $postcode_new != null && $postcode_new != '') {
$new_postcode_id = $this->lookup_model->save_postcode_if_not_exist($postcode_new);
$postcode_data_id = $new_postcode_id ? $new_postcode_id : $postcode_data_id;
}
$vars = array(
'title' => $this->input->post('title'),
'subscribed' => (int)$this->input->post('subscribed'),
'subscribed_active' => (int)$this->input->post('subscribed_active'),
'description' => $this->input->post('description'),
'customer_type' => $this->input->post('customer_type'),
'customer_status' => $this->input->post('customer_status'),
'marketing_status_id' => $this->input->post('marketing_status_id') ? $this->input->post('marketing_status_id') : null,
'marketing_optin_date' => $marketing_optin_date,
'marketing_optin_method_id' => $this->input->post('marketing_optin_method_id') ? $this->input->post('marketing_optin_method_id') : null,
'marketing_contact_method_id' => $this->input->post('marketing_contact_method_id') ? $this->input->post('marketing_contact_method_id') : null,
'marketing_reason_for_leaving_id' => $this->input->post('marketing_reason_for_leaving_id') ? $this->input->post('marketing_reason_for_leaving_id') : null,
'address1' => $this->input->post('address1'),
'address2' => $this->input->post('address2'),
'address3' => $this->input->post('address3'),
'telephone' => $this->input->post('telephone'),
'email' => $this->input->post('email'),
'website' => $this->input->post('website'),
'facebook' => $this->input->post('facebook'),
'twitter' => $this->input->post('twitter'),
'linkedin' => $this->input->post('linkedin'),
'googleplus' => $this->input->post('googleplus'),
'pinterest' => $this->input->post('pinterest'),
'notes' => $this->input->post('notes'),
'number_on_roll' => $this->input->post('number_on_roll'),
'form_entry' => count($this->input->post('form_entry')) > 0 ? $this->input->post('form_entry') : NULL,
'agreement_renewal_date' => $agreement_renewal_date,
'postcode_data_id' => $postcode_data_id,
'services_interested_id' => count($this->input->post('marketing_services_interested_in')) > 0 ? $this->text_helper->get_ids($this->input->post('marketing_services_interested_in')) : NULL,
'organisation_deliveries_id' => count($this->input->post('organisation_delivery')) > 0 ? $this->text_helper->get_ids($this->input->post('organisation_delivery')) : NULL,
);
// marketing emails - when you change the status and also they are subscribed
// we set the date for CRON and also maybe send some email(s)
$send_email = false;
if ($vars['subscribed_active'] && (
!$this->input->post('subscribed_active_date') ||
$original_record['customer_status'] != $vars['customer_status']
))
{
$vars['subscribed_active_date'] = date('Y-m-d H:i:s');
$send_email = true;
}
$user = $this->user_model->get_logged_in_user();
if ($organisation_id = $this->organisation_model->save($vars, $id, $user->id))
{
// save stages
$vars['organisation_current_stages_id'] = '';
$this->lookup_model->delete_lookup_organisations_stages($organisation_id, 'lookup_organisation_stages');
$stages = $this->input->post('organisation_stage_ids');
if ($stages != null && count($stages) > 0)
foreach ($stages as $key => $value) {
$args = array();
$args['organisation_id'] = $organisation_id;
$args['stage_id'] = $value;
$args['created_by'] = $this->input->post('ff_organisation_stage_' . $value) ? $this->input->post('ff_organisation_stage_' . $value) : $user->id;
$args['modified_by'] = $args['created_by'];
$args['id'] = 0;
if ($this->lookup_model->save_lookup_organisations_stages($args, 'lookup_organisation_stages')) {
$vars['organisation_current_stages_id'] .= $value . ' ';
}
}
$this->organisation_model->save($vars, $organisation_id, $user->id);
$this->session->set_flashdata('notice', '<strong>Success!</strong> Item saved!');
}
else {
$this->session->set_flashdata('error', '<strong>Error!</strong> Item not saved!');
}
if ($this->session->userdata('referrer_url')) {
$redirect_back = $this->session->userdata('referrer_url');
$this->session->unset_userdata('referrer_url');
redirect($redirect_back);
}
else {
redirect('/contacts/organisations');
}
}
Модель
public function save($data = array(), $id = 0, $user_id)
{
$existence = $this->get_organization_existence_by_id($id)['existence'];
if ($id && $existence)
{
$data['modified'] = date('Y-m-d H:i:s');
$data['modified_by'] = $user_id;
if (isset($data['notes']))
{
$note = $data['notes'];
unset($data['notes']);
$note_data = array(
'organisation_id' => $id,
'note' => $note,
'created' => date('Y-m-d H:i:s'),
'created_by' => $user_id
);
$this->update_note($id, $note_data);
}
$this->db->where('id', $id);
return $this->db->update('organisations', $data) ? $id : false;
}
else
{
$data['created'] = date('Y-m-d H:i:s');
$data['created_by'] = $user_id;
$data['modified'] = null;
$data['modified_by'] = null;
$note = $data['notes'];
unset($data['notes']);
if (!$this->db->insert('organisations', $data)) return false;
$new_id = $this->db->insert_id();
if ($note)
{
$note_data = array(
'organisation_id' => $new_id,
'note' => $note,
'created' => date('Y-m-d H:i:s'),
'created_by' => $user_id
);
$this->update_note($new_id, $note_data);
}
return $new_id;
}
}
view:
<div id="reason_leaving" class="span2">
<h5>Reason For Leaving</h5>
<div class="controls">
<select name="marketing_reason_for_leaving_id" id="reason_for_leaving" class="span12" data-placeholder="- Select One -" autocomplete="off">
<?php foreach ($lookup_marketing_reason_for_leaving as $r): ?>
<option value="<?= $r->id ?>"<?= set_select('marketing_reason_for_leaving_id', $r->id,
($id ?
($rowdata['marketing_reason_for_leaving_id'] == $r->id ? true : false) :
(strtolower($r->title) == 'active' ? true : false))); ?>>
<?= $r->title ?>
</option>
<?php endforeach ?>
</select>
</div>
</div>