PDA

View Full Version : Softwaredesign using Borderlayout and YUI-MenuBar with PHP?



Wolfgang
21 Dec 2006, 10:17 AM
Hello,

i am looking for a good design to use "BorderLayout" with the YUI-Menubar and PHP to build an Application that is modular in the sense of adding just php "modules" that can be called via the YUI MenuBar. I do not want to touch the code that builds the BorderLayout or the YUI-Menu when adding a new "module" in php.

So basically Borderlayout should act as a sort of Windowmanager with the YUI MenuBar in North.
South should be used for Statusmessages and Center as the main Application Window.
West and east shall be enabled upon request of the application.

The application should start with a php script like index.php that builds the BorderLayout and the YUI-Menu with the items in the javascript world and loads the "default module" where the application usally would start with.

When clicking an Item on the YUI-Menu, a menuitem specific php script should provide its content to one or more regions and open one or more panels within each region as needed.

If another Menuitem is clicked, any previous created panels should be removed, not needed regions hidden and new panels should be created.

Post should still work in the php part, so i assume this will require ajax (yui connectonmanager), to prevent from loading (and thus destroying) the entire page.
To reload and rebuild everytime borderlayout is certainly a bad idea.

Any comments and ideas are welcome :)

Regards

Wolfgang

oj
21 Dec 2006, 7:48 PM
That can be achieved numerous ways. I use a combination of yui-ext, Xajax and Smarty myself.

I use a user interface class to handle the creation of the layout, and then update the center region with new panels. Each menu item can be linked to a function registered with Xajax.

For example, you might have a 'Client Search' menu item that, when clicked, clears any tabs in the center panel and loads the smarty template.

Class instances can be created, or loaded from a stored session, as needed from each of the registered functions registered with Xajax.

This is an example of a function called from a menu item via Xajax:



function call_finances()
{
/**
* Globals
*/
global $objResponse,$dbserve,$ui,$session,$student;

/**
* Data Calls
*/
$invoices=$student->fetch_invoices();
$next_invoice = $student->fetch_next_invoice();

/**
* Map template variables
*/
$ui->assign('next_invoice',$next_invoice);

/**
* Interface
*/
// Clear the current contents
$ui->region_hide_panels($objResponse,'center');

// Call the template
$ui->fetch_panel('finances','panelContent',$objResponse);

$objResponse = $ui->panel_add($objResponse,'center','finances',array("title"=>"Instalment Plan","closable"=>"true"));

// Generate the main grid
$div_id='invoices_outstanding';

$params['headers']=array('INVOICE_NO','ENROL_NO','DUE_DATE','AMT','NAME');
$params['ui_headers']=array('Invoice','Enrolment','Due Date', 'Amount Owing','Fee Name');
$params['handler']="xajax_student_details";
$params['col_properties']['Due Date']['width']=100;
$params['col_properties']['Due Date']['sortable']=true;
$params['col_properties']['Invoice']['sortable']=true;
$params['col_properties']['Enrolment']['sortable']=true;
$params['col_properties']['Fee Name']['sortable']=true;
$params['col_properties']['Amount Owing']['sortable']=true;
$params['col_properties']['Invoice']['width']=50;
$params['col_properties']['Enrolment']['width']=75;
$params['col_properties']['FEE']['width']=100;
$params['col_properties']['Due Date']['renderer']='formatDate';
$params['col_properties']['Amount Owing']['renderer']='money';

$ui->grid($div_id,&$objResponse,$params,'invoices');

return $objResponse;
}



This code would be executed when a 'Finances' menu item is clicked. Obviously it's relying on underlying classes to do much of the work. Being stateless, PHP requires a bit of handling to save on resources. The $student object is created when at login and each time a database lookup is performed (eg., $student->fetch_invoices()) the method first checks to see if the result can be retrieved from the session store. If it can't, then it's retrieved from the db and stored ready for future calls.

The only trick with developing a framework to handle this is the sequencing of events. The place in your index.php that you have Xajax stopping and waiting for requests is critical.

I use config files (plain text .ini for database connection data, etc, and php config files to set program default areas and a library of available 'panels' that Smarty can call upon) to do much of it, and then call on the globals via the Xajax functions linked to menu items.

The functions called via Ajax are very simple--they just put together the building blocks available from the framework. All of the grunt work should be kept elsewhere.

Cheers

OJ.

Wolfgang
22 Dec 2006, 12:39 AM
Thank you for responding.

My goal is that the main index.php reads the available modules (which are php scripts in their own subdir) and builds the menu and the links for the menu to these modules. Eeach module defines its menuitems and a function that is associated with this menuitem.
So when a new module is done, it would show up automatically in the menu and would be callable, without having to touch the main index.php.

I used xajax in the past as well. The only thing why i thought to use the YUI Connectionmanager is, that xajax requires the registration of functions on pageload. With the YUI Connection Manager, i can just call any php script at runtime.
So my problem was, how can i use xajax on the main index.php to call the modules, when i do add a module, but do not want to touch the main index.php?

But it seems you are using xajax from your UI class just to interface to borderlayout, and this way the registered callback functions for xajax would not be content dependant and therefore would not change.
Like: $ui->assign(), $ui->fetch_panel(), $ui->panel_add()
Is this correct?

Can you post your UI Class?

Best regards

Wolfgang

oj
22 Dec 2006, 2:13 AM
The difficulty with making a framework automatically 'aware' of the modules is that it would need to scan through the directories at startup to check what's there, which would increase the load time. If the modules are likely to be very dynamic, that is they change regularly on a day-to-day basis, this may be acceptable.

The way I do it is with a 'ui.defs.php' file. This file contains definitions for all of the modules and includes the display name, the name of the Smarty template file, side and sub-menus, etc. It produces a library which is loaded by the ui class so that when I call a panel ($ui->fetch_panel()) it knows what to load up. It provides a simple place to make additions to the modules and change the module details. I often have a defs file in each individual module as well that configures the module.

I still need to register the functions via xajax, however this could be achieved at startup by loading a module definition file from the module directory. That way the framework need only know the name of the module, from a config file, and can go and retrieve everything it needs from the module directory.

In each individual module directory, I'd suggest having a definition file for user interface components, another for the xajax registrations, and the php file with the functions provided by the module.

The ui class acts as a wrapper for dynamically generating the BorderLayout components (eg, creating a dialog, adding a tab panel, creating a grid, etc), and also has methods for the general framework, such as setting the system title, holding the module definitions, etc.

Hope this helps!

Wolfgang
22 Dec 2006, 2:43 AM
The difficulty with making a framework automatically 'aware' of the modules is that it would need to scan through the directories at startup to check what's there, which would increase the load time. If the modules are likely to be very dynamic, that is they change regularly on a day-to-day basis, this may be acceptable.


Yes this is true. However the code is already written and i think because it has to be loaded only one time on startup when building the main page, it will be acceptable.
In fact that is one of the advantages i see when building the gui based in javascript (borderlayout). Using classic php with for example smarty, it loads the entire page every time, including the menu stuff etc.

Do you use things like SetURL() to assign/load content to panels, or do you assign anything via xajax only?

Do you keep/reuse panels or do you add/remove them upon request?

Regards

Wolfgang