TreeConnector : undefined index when using set_userdata

Hi,
I need to include user data from database fields in the Xml tree generated but I always log an “undefined index” error in the PHP error log file. The user data is included in the xml generated but the error is always in the error log … what is the problem ?

Best regards, Frédéric.

 $tree = new TreeGroupConnector($link);
 ...
 function setUserData($item) {
	$item->set_userdata("etatTerrain", $item->get_value("etatTerrain"));
 }
 $tree->event->attach("beforeRender","setUserData");
 $tree->render_table($idTable, "idx", $champTable, "", $groupeTable);

is “etatTerrain” included in $champTable ?
Such message can occurs when you are accessing data which is not mentioned in render config.

Yes, etatTerrain is an existing database field and it is include in the variable $champsTable (“etatBorne,etatTerrain”) … I have the same problem with other database tables. The user data is always right but I have a PHP notice as of it :

 [09-Feb-2012 14:01:52] PHP Notice: Undefined index: etatTerrain in D:\wamp\www\knm.new\php\dhtmlx\base_connector.php on line 176

Best regards

Hi Stanislav,
any idea about my problem ?

I copy hereunder the code of my Tree connector and the results I got :

[code]

<?php session_start(); require_once("dbClients.php"); $link=mysql_connect($mysql_server,$mysql_user,$mysql_pass); mysql_set_charset('utf8',$link); $db_selected = mysql_select_db($mysql_db); require("dhtmlx/treegroup_connector.php"); $tree = new TreeGroupConnector($link); // Table à utiliser $idTable=""; if (isset($_GET['idTable'])) $idTable=$_GET['idTable']; // Groupement de la table $groupeTable=""; if (isset($_GET['groupeTable'])) $groupeTable=$_GET['groupeTable']; // Champ de la table $champTable=""; if (isset($_GET['champTable'])) $champTable=$_GET['champTable']; function setUserData($item) { $item->set_userdata("etatTerrain", $item->get_value('etatTerrain')); } $tree->event->attach("beforeRender","setUserData"); $tree->render_table($idTable, "idx", $champTable, "", $groupeTable); ?>[/code]

Xml output :

<tree id="0">
<item id="ES__{group_param}" text="ES" child="-1">
<userdata name="etatTerrain">
<![CDATA[ ]]>
</userdata>
<item id="14" text="CAF 63 (EGT-a-0030)">
<userdata name="etatTerrain">
<![CDATA[ ES ]]>
</userdata>
</item>
<item id="93" text="CC Nord Limagne (EGT-u-0111)">
<userdata name="etatTerrain">
<![CDATA[ ES ]]>
</userdata>
</item>
<item id="99" text="Sioulet Chavanon (EGT-u-0117)">
<userdata name="etatTerrain">
<![CDATA[ ES ]]>
</userdata>
</item>
<item id="106" text="CC de Gentiane (EGT-u-0124)">
<userdata name="etatTerrain">
<![CDATA[ ES ]]>
</userdata>
</item>
<item id="107" text="Rochefort Montagne (EGT-U-0137)">
<userdata name="etatTerrain">
<![CDATA[ ES ]]>
</userdata>
</item>
</item>
</tree>

The connector.log file :


====================================
Log started, 14/02/2012 07:02:56
====================================

idTable : tree_bornes_Parc_Etat

groupeTable : etatTerrain

champTable : etatBorne,etatTerrain

SELECT DISTINCT `etatTerrain` as value FROM tree_bornes_Parc_Etat

Undefined index: etatTerrain at D:\wamp\www\knm.new\php\dhtmlx\base_connector.php line 176

SELECT `idx`,`etatTerrain`,`etatBorne`,`etatTerrain` FROM tree_bornes_Parc_Etat WHERE `etatTerrain` = 'ES'

Done in 0.046041011810303s

Thanks for provided info, it is clear why error occurs, but nor clear hot to prevent it :slight_smile:

You are using tree-group connector, so to get items on first level separate sql query executed, which has not etatTerrain as named field ( first sql query in log ), and while executing your command it fails to get_value.

We will try to update connectors, so they will provide valid names instead of value alias for top level request. Meanwhile you can just ignore message, as it is not related to any serious issues in code.