Get KoolPHP UI with 30% OFF!

Advanced Array Data Source : Array Exists Check Needed

Anthony Amolochitis
The method in reference is the GetFields() method in the AdvancedArrayDataSource.php file.
I received the following errors.
Notice: Undefined offset: 0 in C:\wamp\www\order\KoolPHP\KoolControls\KoolGrid\ext\datasources\AdvancedArrayDataSource.php on line 108
Warning: Invalid argument supplied for foreach() in C:\wamp\www\order\KoolPHP\KoolControls\KoolGrid\ext\datasources\AdvancedArrayDataSource.php on line 108
function GetFields()
	{
		$_fields = array();
		foreach($this->_Data[0] as $_key=>$_value)
		{
			$_field = array("Name"=>$_key,"Type"=>gettype($_value),"Not_Null"=>false);
			array_push($_fields,$_field);
		}
		return $_fields;
	}

I did the following to apply the remedy to the problem. If you guys could do a permanent fix, I would greatly appreciate it so that I do not have to fix it each time I upgrade.
function GetFields()
	{
		$_fields = array();
                if(isset( $this->_Data[0] ) )
                {
                    foreach($this->_Data[0] as $_key=>$_value)
                    {
                            $_field = array("Name"=>$_key,"Type"=>gettype($_value),"Not_Null"=>false);
                            array_push($_fields,$_field);
                    }
                    return $_fields;
                }
	}
Posted Oct 29, 2015 , edited Oct 29, 2015 Kool -
David
Hi Anthony,
Thanks for your feedback! We would make this fix for the future release of KoolGrid's data sources.
Rgds,
Posted Oct 30, 2015 Kool
Riya
You could use array_key_exists() twice to check if the key exists.
if (array_key_exists("story", $arr) AND array_key_exists("message", $arr)) {
// Both keys exist.
}
Posted Nov 9, 2016 Kool