php - Correctly Passing data from Controller to View CodeIgniter -


this question may asked numerous times facing difficulty in doing so. var_dump($lex_post_data); works fine on controller

my controller code

try{                 // need manage functionality initialized.                 $manage_mode        = false;                 $appointment   = array();                 $provider      = array();                 $customer      = array();                 $lex_post_data = $this->input->post('lexname');               var_dump($lex_post_data);             // load book appointment view.             $view = array (                 'available_services'    => $available_services,                 'available_providers'   => $available_providers,                 'company_name'          => $company_name,                 'manage_mode'           => $manage_mode,                 'appointment_data'      => $appointment,                 'provider_data'         => $provider,                 'customer_data'         => $customer,                 'post_data'             => $lex_post_data             );          } catch(exception $exc) {             $view['exceptions'][] = $exc;         }          $this->load->view('appointments/book', $view); 

view code:

<script type="text/javascript">     var globalvariables = {         availableservices   : <?php echo json_encode($available_services); ?>,         availableproviders  : <?php echo json_encode($available_providers); ?>,         baseurl             : <?php echo '"' . $this->config->item('base_url') . '"'; ?>,         managemode          : <?php echo ($manage_mode) ? 'true' : 'false'; ?>,         appointmentdata     : <?php echo json_encode($appointment_data); ?>,         providerdata        : <?php echo json_encode($provider_data); ?>,         customerdata        : <?php echo json_encode($customer_data); ?>,         lexpostdata         : <?php echo json_encode($lex_post_data); ?>,         csrftoken           : <?php echo json_encode($this->security->get_csrf_hash()); ?>     };     console.log(globalvariables);     var ealang = <?php echo json_encode($this->lang->language); ?>;     var availablelanguages = <?php echo json_encode($this->config->item('available_languages')); ?>;      $(document).ready(function() {         frontendbook.initialize(true, globalvariables.managemode);          // generalfunctions.centerelementonpage($('#book-appointment-wizard'));         generalfunctions.enablelanguageselection($('#select-language'));     }); </script> 

ques1: correct way of accessing values sent controller. ques2: on console.log(globalvariables); getting

lexpostdata : null  

what doing wrong.

please guide

edit

solved & closed: trying differnt name varriable on view. had use

lexpostdata         : <?php echo json_encode($post_data); ?>, 

instead of

lexpostdata         : <?php echo json_encode($lex_post_data); ?>, 

in controller passing $lex_post_data in post_data

'post_data'         => $lex_post_data 

so in view instead of

 <?php echo json_encode($lex_post_data); ?> 

use

<?php echo json_encode($post_data); ?> 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -