-3

I have a bug, please tell me what could be the problem

Type: ErrorException Code: 8 Undefined index : db_sub_form_move_to_topleft Line : 113

Here my code:

23 public function index() {
24  $company_id = Session_Helper::getSessionCompanyId();
25  $employee = Session_Helper::getSessionEmployee();
26
27  //search company settings like approval process
28  $company_profile = $this->dm->find(Company::class, $company_id);
29  $company_settings_options = $company_profile->getSettings();
30  $enable_modules = [];
31  $settings_view_data = [];
32  if (!empty($company_settings_options)) {
33      $enable_modules = $company_settings_options->getEnabledModuleIds();
34      $settings_view_data = $company_settings_options->getViewData();
35  }


112 $data = [
113         'record_db_sub_form_move_to_topleft' => $settings_view_data['db_sub_form_move_to_topleft'],
114         'record_db_sub_form_pending_bgcolor' => $settings_view_data['db_sub_form_pending_bgcolor'],
115         'record_db_sub_form_backcolor' => $settings_view_data['db_sub_form_backcolor'],
116         'record_employee' => $employee_count,
117         'record_form' => $form_count,
118         'record_submitted_form' => $submitted_form,
119         'record_risk_assessment' => $risk_assessment_count,
120         'record_form_group' => $form_group_count,
121         'record_vehicle' => $vehicle_count,
122         'reference_document_count' => $reference_document_count,
123         'record_docket_count' => $docket_count,
124         'chart_employee' => Dashboard_Statistics_Helper::getEmployeeCountByCompany($company_id),
125         'chart_submissions' => Dashboard_Statistics_Helper::getSubmittedForms($company_id),
126         'chart_route_plan' => in_array('enable_securatrak_tracking',$enable_modules) ? Dashboard_Statistics_Helper::getRoutePlanStatus($company_id) : null,
127         'chart_completed_journey' => in_array('enable_securatrak_tracking',$enable_modules) ? Dashboard_Statistics_Helper::getCompletedJourney($company_id) : null
        ];
Khánh Gia
  • 11
  • 1
  • 1
  • 1
    Format your code properly remove line numbers from starting – B. Desai Oct 06 '17 at 10:55
  • 1
    Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – B. Desai Oct 06 '17 at 10:57

1 Answers1

0

this means that this array $settings_view_data doesn't contain the key u r trying to get. so u have to option:

1 -> check this function getViewData() and make sure that it returns an array that contains the key 'db_sub_form_move_to_topleft'.

2 -> check if key 'db_sub_form_move_to_topleft' exist before getting it and that by user isset() like this :

$data = [
 'record_db_sub_form_move_to_topleft' => isset($settings_view_data['db_sub_form_move_to_topleft']) ? $settings_view_data['db_sub_form_move_to_topleft'] : '',