Welcome Guest, Not a member yet? Register   Sign In
Passing arrays to views and undefined variables.
#1

[eluser]stevefink[/eluser]
Folks,

I'm trying to pass $dataArr to my view via the following method:

Code:
$dataArr['error'] = '';
        if($current_carfax)
        {
            $dataArr['current_carfax'] = $current_carfax;
        }
        else
        {
            $dataArr['current_carfax'] = '';
        }
        
        //log_message('debug', "Data ARRAY: ".print_r($dataArr, TRUE));
        // This loads the initial view if no $_POST or $_FILES array exists.
        $this->load->view('console/car_fax_view',$dataArr);

I'm explicitly setting $dataArr['current_carfax'] to an empty string here. Is there a reason my view will complain that $current_carfax is an undefined variable? Shouldn't the above fix that? It fixes it for $error, that's for sure.

In the loop that checks if the variable should be declared before that code is this:

Code:
$is_enabled = $this->autodb->update_carfax($vehicle_id);
            
            if($is_enabled)
            {
                foreach( glob("$carfax_loc/$vehicle_id" . "*.*") as $file)
                {
                    $current_carfax = substr($file,1);
                }    
            }
            else
            {
                $current_carfax = '';
            }

Thanks for any insight.
#2

[eluser]coolfactor[/eluser]
I'd look at this code:
Code:
foreach( glob("$carfax_loc/$vehicle_id" . "*.*") as $file)
{
    $current_carfax = substr($file,1);
}

I'm not sure what you're trying to do there. Is it possible that a NULL value is being set to $current_carfax, hence leading the view to complain the variable is undefined, even though it wasn't in the controller?

Variables that contain NULL probably won't be set in the view.




Theme © iAndrew 2016 - Forum software by © MyBB