0
votes

My $data array is not getting passed to the view per the code and errors shown below.

public function myAccount(){
    $data = array(
        'templateVersion'   => 'template1',
        'headerVersion'     => 'header2',
        'css'               => '',
        'navBarVersion'     => 'navBar2',
        'main_content'      => 'myaccount/myAccount',
        'page_title'        => 'example.com - My Account',
        'footerVersion'     => 'footer2'
        );
    if (($this->session->userdata('is_logged_in')) == 1) {
            $config['upload_path'] = $this->logo_path;
            $config['allowed_types'] = 'gif|jpg|png|jpeg';
            $config['encrypt_name'] = TRUE;
            $this->load->library('upload', $config);    
               if ($this->input->post('upload')) {
                    if(!$this->upload->do_upload('userfile')){
                        echo $this->upload->display_errors('<p>', '</p>');
                    } else {
                        $w = $this->upload->data();
                        $data = array(
                            'field_input_name' => $w['file_name'],
                            );
                         //$this->db->insert('table_image', $data);
                         echo "here";
                         //exit;
                    }
                }

            //******************************************
            // For some reason, $data is not passed in!
            // Have posted the web screen error far below.
            $this->load->view('includes/template1', $data);  

    }else{
        redirect('site/restricted');
    }
}

////////////////////////////////////////////////////////////////////

A PHP Error was encountered Severity: Notice Message: Undefined variable: headerVersion Filename: includes/template1.php Line Number: 4

An Error Was Encountered

Unable to load the requested file: includes/.php

2

2 Answers

1
votes

You have initialised $data twice. Once in the beginning of the function and again in else condition of upload.Inside else condition of upload change like this

 $data['field_input_name'] = $w['file_name'];

It will work.

0
votes
$data array's keys are converted into variables
$data['someKey'] = array(
        'templateVersion'   => 'template1',
        'headerVersion'     => 'header2',
        'css'               => '',
        'navBarVersion'     => 'navBar2',
        'main_content'      => 'myaccount/myAccount',
        'page_title'        => 'example.com - My Account',
        'footerVersion'     => 'footer2'
        );

In view you can access as print_r($someKey); use die(var_dump($someKeys)); in view to see results

As you are trying to upload images in CI you can use echo $this->image_lib->display_errors(); for some other error detection or debugging