Loading a part of a .glade file

In large projects, you might have many windows defined in your .glade file, and all are loaded when loading the .glade file. That a) slows down the start of your application and b) shows all windows immediately, if you didn't set their visibility to hidden in Glade. Further, you may want to signal_autoconnect_instance() only a part of the .glade file to one object, while connecting another part to another object.

The solution to this problem is the second parameter of the GladeXML constructor: Just pass the id of the to-be root widget, and only this part of the .glade file will be loaded.

Example 4.6. Partially loading a .glade file

<?php
//Loading a part of the glade file only

//We want "btnClose" to be the root of the widget tree to load
$glade = new GladeXML('helloglade.glade', 'btnClose');

//That will work
$btn = $glade->get_widget('btnClose');

//This will fail, as the window isn't loaded:
$window = $glade->get_widget('wndClose');
//Output is NULL
var_dump($window);
?>