Application Structure

I love how Richard Heyes’ Application Structure post which describes his way of layint out PHP applications is similar to my own personal structure. I have been using something very similar for a few years now, which evolved by working with PHP applications and dealing with problems and how to avoid them in the future, so it’s amusing to see two people come up with something so similar.

I basically agree with the way he separates library code from normal PHP scripts that are available to the Web, but I do things a bit different. I use the following directory structure:

application root
  +- crons
  +- include
  |    +- jpgraph
  |    +- pear
  |    +- Smarty
  +- locks
  +- logs
  +- scripts
  +- setup
  +- templates
  +- templates_c
  +- webroot
       +- css
       +- images
       +- js


  • crons: where scripts that run off the crontab are located.
  • include: the main directory where the business logic classes are located. I also store PEAR, Smarty and Jpgraph classes here since I don’t really need to see them on the top-level directory every time I want to browse for a file. Richard couldn’t be more right about the whole idea of bundling the libraries that you depend on with your application. There’s nothing worse than waking up one day and having your code totally broken because someone upgraded PEAR to the latest release.
  • locks: scripts that run off the crontab save their lock files to avoid having two copies of the same script running at the same time. Since I cannot simply trust PHP to create a temporary file on the appropriate place, I’ll create my own directory for this.
  • logs: where assorted error logs and informative debugging logs are stored.
  • scripts: where other types of scripts are located, such as manual scripts that are available for convenience. In some cases this might not be needed.
  • setup: where configuration related files are stored. The all-mighty file is stored here, as well as database schema files and etc.
  • templates: where smarty template files are stored.
  • templates_c: smarty uses this directory to save compiled templates.
  • webroot: the actual web accessible directory of the application, from which PHP scripts will include the configuration file, business logic classes, Smarty and etc.

So what do I have on my

< ?php
ini_set('display_errors', 1);
// define the constants related to the structure
@define('APP_ROOT_PATH', '/www/htdocs/appname/');
@define('APP_PATH', APP_ROOT_PATH . 'docs/');
@define('APP_INC_PATH', APP_ROOT_PATH . 'include/');
@define('APP_PEAR_PATH', APP_INC_PATH . 'pear/');
@define('APP_SMARTY_PATH', APP_INC_PATH . 'Smarty/');
if ((stristr(PHP_OS, 'darwin')) || (!stristr(PHP_OS, 'win'))) {
    ini_set('include_path', '.:' . APP_PEAR_PATH);
} elseif (stristr(PHP_OS, 'win')) {
    ini_set('include_path', '.;' . APP_PEAR_PATH);
@define('APP_SETUP_PATH', APP_ROOT_PATH . 'setup/');
@define('APP_LOG_PATH', APP_ROOT_PATH . 'logs/');
@define('APP_ERROR_LOG', APP_LOG_PATH . 'errors.log');
@define('APP_LOCKS_PATH', APP_ROOT_PATH . 'locks/');
// ...

Then in each PHP script on the webroot directory, I do something like this:

< ?php
include_once(APP_INC_PATH . 'class.auth.php');
include_once(APP_INC_PATH . 'class.template.php');
include_once(APP_INC_PATH . 'class.db_connection.php');
// ...

And you go from there. I like Richard’s idea to use basename() to get the base directory dynamically.

Connecting TiVo to your secure wireless network

So I just spent an hour trying to properly configure TiVo so that it would connect to my secure wireless network, and here are the details for the next guy searching on Google for this…

Wireless Router: Linksys WRT54G
USB Wireless Adapter: Netgear WG111
Secure Wireless Settings: WEP 128 bits

The problem was that my router was setting the WEP key to the third key choice (I get 4 different keys for each passphrase), and TiVo only works with the first one. The router was also set to ‘Auto’ on Authentication Type on the “Advanced Wireless Settings” screen, and I had to change it to ‘Shared’.

After changing the two things above, my TiVo started working right away and it is now downloading updates.

Web 2.0 my ass

So I’m playing with for a side project, trying to create a <DIV> that will slide into and out of view, but something is not working quite right. When I use the Effect.SlideDown() and then Effect.SlideUp() repeatedly, it will continuously grow the height of the element.

Everything seems to be fine, the documentation tells me that I’m doing the right thing, which is to create two <DIV>s, but somehow it doesn’t work on my version, but it works perfectly at the demonstration page on the website. Even the bug entry about it says that in order to fix it, I should simply use block level elements, which I’m doing.

So here’s the fix for this if someone else ever hits the same problem:

Don’t use:


like a real monkey should to make your HTML code easier to read, but rather this:


Doing that fixes this apparent bug, which makes no sense to me.

Eventum presentation at Houston PHP Users Group

Yesterday I gave an introduction to Eventum at the June meeting of the Houston PHP Users Group. You may read the presentation below from Slideshare.

SlideShare | View

Getting up to date on contributions

So the last few months were pretty busy at work, and I had not much free time to handle Eventum patches/contributions from the community, so I’ll be catching up for the next few days and make sure we are going through the process of merging those changes into the next release of Eventum.

The community as a whole seems to be growing at every release we do, and we will try to release more often in the future. The next 1.5 release of Eventum should have some pretty nice features, like per-project permissions and etc that Bryan was working on.

« Previous Page« Previous entries « Previous Page · Next Page » Next entries »Next Page »