YUI PHP Loader Utility: Mixed Loading Methods

In this example, we bring YUI components onto the page using a mixture of static and dynamic loading methods. A static script include is used to bring in the Yahoo Global Object, the Dom Collection, the Event Utility components. The YUI PHP Loader Utility is used to load the Calendar component. This example implements YUI PHP Loader via a YAHOO_util_Loader instance. We include the YUI PHP Loader script file, then specify in configuration which component we want loaded on the page, which components to skip loading since they are already present on the page, and what we want to do once everything is loaded.

This example loads in new window to demonstrate a somewhat more advanced use case — a page with no other content, wherein the Loader is introducing YUI into a simple context.

Advanced Use Case: Mixed Loading Methods

This example implements the YUI PHP Loader Utility to load the Calendar Control.

The workflow happens in four steps:

  1. Include the YUI PHP Loader class file
  2. Create a YAHOO_util_YUILoader instance: Set configuration flags as needed, call the load method with a list of components to load, notify the loader of any modules to avoid loading, and define what to do once the components are loaded (in this case, once the components are loaded we instantiate a Calendar Control on the page).
  3. Ouput YUI CSS <link> nodes
  4. Ouput YUI JavaScript <script> nodes

Here's what that looks like in terms of raw source — this is the full source code for this example:

This code executes the following steps in order:

  1. YUI PHP Loader loads taking the configuration settings into account. It gets instructions about what components are required and how to configure them.
  2. YUI PHP Loader checks the dependency tree. Loader knows that the Calendar component requires the Yahoo Global Object, the Dom Collection, and the Event Utility components. Normally the loader would bring these dependencies into the page for us, but in this case the setLoaded method was used to have the loader avoid loading these resources since they were already included via a static script node.