Also available for download from the Zoop site (or SourceForge) is the Zoop Skeleton. This is a barebones application provided so that a programmer could have a starting point when beginning a new application. A new skeleton would likely be released with each new Zoop release so it is usually a good idea to get the skeleton that corresponds with your Zoop release.
The skeleton contains a number of files and directories of which some files are worth mentioning here * READ: THESE ARE IMPORTANT *.
config.php includes.php templates/default config/
We will look at a few of these files and directories individually to ensure our application turns out as well as it should.
This is your primary configuration file for your application. It contains a lot of defines to setup the options Zoop will use for your application. Mostly the defaults will work for you until you know enough to change them.
There is one setting however that will prevent your entire application from working until it is set properly. This is the location of Zoop on your system. It looks like this:
define('zoop_dir', '/home/steve/Projects/zoop');
That is where Zoop exists on my system and would be very unlikely in the same place on yours. Please change this to the appropriate location. Another important one is the app_status definition. Though we won't use it for the hello world application, it is one to make a note of. It can be dev, test or live and Zoop will handle things like errors and caching differently depending on the app_status.
The next most important file is the includes.php file. A lot of things won't work if this file isn't used properly, luckily it is really easy to use. There are five sections of this file, configuration, zones, objects, misc, and pear.
This section includes files like config.php and zoop.php. After that it sets up the zoop object which will be used for the rest of the file. The first thing we do after we have the Zoop object is use it to include the different components of zoop that our application will use. By only including the parts we use we help to eliminate application bloat a problem that many frameworks suffer from (most think of it as a necessary evil). Zoop based application can actually run really lean by simply only including the components you plan on using. For our hello world application we will only include the gui component. This is done with the function call:
$zoop->addComponent('gui');
Make sure all other addComponent calls are commented out and this call for gui isn't.
This section includes all the zones that we will be using in our application. *This is important* When you create a new zone don't forget to include it here. This is done with the function call:
$zoop->addZone('zonename');
For our hello world application we will only be using the default zone so make sure that only that line is uncommented.
This section is used to include objects. Objects are libraries that you use for your application. These could be objects (classes) or static functions (though it is usually a good idea to classify everything to avoid collisions in the global namespace). A good example of this would be if you were to write a webmail application you would want to create an object containing some IMAP or POP functions that could be used by your page functions. These objects are located in app_dir/objects and can exist in subdirectories. The are included with the function call:
$zoop->addObject('objectname');
Notice that we do not put the .php after the object name in the function call.
This section is up to you and is put here for organizational purposes. Just use standard php include or include_once here.
This section is for pear libraries that you need for your application. Zoop also uses pear for different things, but each component includes it's necessary pear libraries itself. It is always a good idea to use include_once when including pear libraries as you are not sure which pear libs Zoop will include (also using include_once) in the future. As a general rule Zoop only uses pear libraries when there is a compelling reason to do so. A good example of this is pear_DB an excellent database abstraction library which quickly surpassed the one we wrote in Zoop previously.
In a Zoop application, when a web browser visits the http://example.com/application_dir/
Zoop will always execute the same page function. pageDefault inside of zone_default.php. The skeleton actually already has a welcome page there setup so lets go there in our web browser and make sure that we see what we want to see (it should be a welcome screen of some sort). If you see an error message instead retrace your steps. One step that many people forget is to make sure that the web server can write to the app_dir/tmp directory. That is where the template caching files are located and Zoop will display an error message if it cannot create them.
If you are reading this it is safe to assume that you have come thus far unscathed. You are almost there with your first Zoop application.
Edit zone_default.php with your favorite PHP editor. If you don't have a favorite PHP editor allow me to recommend some that I have enjoyed using. On Linux or Mac I love Quanta Plus. On Windows notepad++ is pretty nice and so is PHP Designer 2006. Of course there is always vim for any os. So back to zone_default.php, edit it and find the function called pageDefault. It already has some content in it, but we don't need to use that content, so comment it out or delete it. We should be left with a pageDefault function looking like this:
pageDefault($inPath) { }
Now lets place something into that function. Since this is a "hello world" app, we obviously want to echo ("hello world");. Your pageDefault should look like:
pageDefault($inPath) { echo("Hello World"); }
Now to view your application. In your web browser go to http://example.com/app_dir/