Codeigniter 2.2.2 / How to print array data in a View that is passed from a controller?

I am not receiving any of the "country" data that I am passing from my controller to my view. Here is my controller:

    public function country_destination()
{

    $this->load->model('model_admin');
    //Calling the get_unique_states() function to get the arr of state. Model already loaded.
    $arrCountries = $this->model_admin->get_unique_countries();

    //Getting the final array in the form which I will be using for the form helper to create a dropdown.
    foreach ($arrCountries as $countries) {
        $arrFinal[$countries->country] = $countries->country;
    }
    $data['countries'] = $arrFinal;

            // Basis page data
            $data = array(
                'templateVersion'   => 'template1',
                'headerVersion'     => 'header1',
                'css'               => '<link rel="stylesheet" href="/css/compiled/index.css" type="text/css" media="screen" />
                                       <link rel="stylesheet" type="text/css" href="/css/lib/animate.css" media="screen, projection" />',
                'navBarVersion'     => 'navbar1',
                'main_content'      => 'detail-wrap/admin/country_destination', 
                'page_title'        => 'example.com - App',
                'footerVersion'     => 'footer1'
                );
            //echo "here";
            $this->load->view('detail-wrap/includes/template1', $data);      
}

      

In my opinion, I would like to dump the content of $ data, which includes $ data [countries]. This will help me determine if "some" data is actually being transferred and help me with further debugging.

I've tried print_r ($ data); but I am getting undefined: data 'error.

+3


source to share


2 answers


NOTE. array keys are $data

converted to variables

You must do

print_r($countries);  //to print the countries

      

in your view



You must specify key

for this array

 $data['somekey'] = array(
                'templateVersion'   => 'template1',
                'headerVersion'     => 'header1',
                'css'               => '<link rel="stylesheet" href="/css/compiled/index.css" type="text/css" media="screen" />
                                       <link rel="stylesheet" type="text/css" href="/css/lib/animate.css" media="screen, projection" />',
                'navBarVersion'     => 'navbar1',
                'main_content'      => 'detail-wrap/admin/country_destination', 
                'page_title'        => 'example.com - App',
                'footerVersion'     => 'footer1'
                );

      

And access this data in the view using a key. CI sends the key as a regular php variable toview

So from the view you can access like print_r($somekey)

+2


source


In your view file, you can write to display the array data in a structured format.



echo "<pre>";

print_r($countries);

      

0


source







All Articles