X-core
@X-core
начинающий веб разработчик

Как устранить ошибку в методе save()?

Работаю с чужим кодом, фреймворк Codegniter практически не знаю, приходилось с другими фреймворками работать, но не суть.
Функционал реализовал(выпадающий список с выводом данных,который пользователь добавил на отдельной странице).
Но при сохранении получаю ошибку: Error Item not saved! Если убираю строку отвечающую за мой функционал (
'marketing_reason_for_leaving_id'  => $this->input->post('marketing_reason_for_leaving_id') ? $this->input->post('marketing_reason_for_leaving_id') : null
,
), то сохранение срабатывает. Не могу понять как это можно исправить.
Вар дамп массива $vars :
array(29) { ["title"]=> string(2) "р" ["subscribed"]=> int(1) ["subscribed_active"]=> int(0) ["description"]=> string(2) "р" ["customer_type"]=> string(8) "customer" ["customer_status"]=> string(8) "enquirer" ["marketing_status_id"]=> string(2) "16" ["marketing_optin_date"]=> NULL ["marketing_optin_method_id"]=> NULL ["marketing_contact_method_id"]=> NULL ["marketing_reason_for_leaving_id"]=> string(1) "1" ["address1"]=> string(0) "" ["address2"]=> string(0) "" ["address3"]=> string(0) "" ["telephone"]=> string(0) "" ["email"]=> string(0) "" ["website"]=> string(0) "" ["facebook"]=> NULL ["twitter"]=> NULL ["linkedin"]=> NULL ["googleplus"]=> NULL ["pinterest"]=> NULL ["notes"]=> string(0) "" ["number_on_roll"]=> string(0) "" ["form_entry"]=> string(0) "" ["agreement_renewal_date"]=> NULL ["postcode_data_id"]=> NULL ["services_interested_id"]=> NULL ["organisation_deliveries_id"]=> NULL }

Мой инпут с названием "marketing_reason_for_leaving_id" и равен 1,как выяснилось это айди взначения в . Данные в выпадающем списке получаю из таблицы БД.

Контроллер:
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');
		}
	}

Вьюха:

<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>
  • Вопрос задан
  • 65 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы