PHP script with PEAR to create a tree interface

How to create a tree-view in PHP in a fast and comfortable way, using a PEAR package to implement the tree.

I’m looking for a script to create the typical tree system to display content that expands and contracts when its branches are clicked, something that we’ve undoubtedly seen working hundreds of times on other web pages or as an interface for operating systems or other applications . My idea was to find the development already created, which could be quickly implemented in a web application and I have located a ready system that could be useful.

The system to create the tree is a PEAR package, a well-known and widely used PHP framework. Specifically, the package is called HTML_TreeMenu and we can find it in the URL:

So that you can see the online tree interface, I have placed a .

Like any PEAR package, in principle we have to install it through PEAR’s own package manager, since it would be the most appropriate to maintain our system’s packages. To do this, we must have installed PEAR on our server beforehand, something that we already discussed in , for Windows systems.

However, for those of you who don’t have PEAR installed and don’t want to bother with those details, the HTML_TreeMenu package, like any other, has a manual download and install option. Also, for the case at hand, the best thing is that HTML_TreeMenu does not have dependencies with other packages, so we can install it anywhere on our server and it will work autonomously. The only thing that we will have to take into account is the routes of the includes that will have to be placed in this library.

See also  Technologies for advanced target development

To obtain the HTML_TreeMenu package we can go to the download page of the package and download the link marked “Download”, next to the text “For manual installation only”.

With the download we will obtain a compressed file with code, which in reality, since it does not depend on other PEAR packages, we can place in any directory on our server. The download package itself has a folder called “docs” with the user manual and a usage example in the file example.php. This example is ready to work directly, as long as we respect the directory structure that the package has once uncompressed, so we should see it working without any further problems.

Note: the only detail that we can find that doesn’t look quite right, is that this system is built using some deprecated (obsolete in PHP5) use of PHP, so we will find that, if we run it on a current PHP installation, some “Strict Standards” alert messages. They are not error messages and the application will work correctly, but of course these error messages are quite annoying. We can simply remove them with the line of code: error_reporting(0);

Some interesting functionalities that this PEAR package supports us for the creation of dynamic trees are:

  • Ability to create dynamic trees and trees in a simple SELECT form field.
  • DHTML Cross-Browser, that is, compatible with all browsers.
  • It remembers the state of the tree (with its open or closed branches) in successive accesses, by means of cookies.
  • Possibility of detailed configuration of each one of the nodes, such as the CSS class they must have, the ability to say if they must appear open or closed, the links to which they must direct, the events to be applied, etc.
  • Full use of CSS to apply styles, which can be assigned to all nodes globally or to particular nodes.
  • Various images of folders, to customize the tree to our liking. Or the possibility of creating our own images.
See also  What is Adobe AIR?

In the next article we will see how HTML_TreeMenu to create the DHTML tree interface.

Loading Facebook Comments ...
Loading Disqus Comments ...