All in vain

Some rants about technology, PHP, people, tools, web etc from a developers perspective. Feel free to copy ideas, code or anything from here.

Thursday, December 14, 2006

Guide to application development with PHP

No comments
I know it sounds too ambitious but couldn't help but dig it ;) . Well if you have dipped your toes in PHP and you are comfortable working with PHP this guide is for you. If you are unsatisfied with the current way of structuring your application then this guide might help you.

So lets start with the folder structure. The way you structure your application is crucial. Here is what i have come up with. This structure is only suggestive, you are free to modify it to suit your taste.



  • Classes: Store all your classes and helper code here.
  • Conf: This holds your configuration files needed for your application.
  • Cron: Holds all files which needs to run as cron job.
  • Includes: Store all your function files here.
  • Js: Javascript code plus any helper code like WYSIWYG editor etc.
  • Locale: Create folders for every language you plan to support and create language files which you can call depending upon the configuration settings.
  • Pages: All the pages which perform some directly visible action are stored here. Rest can be stored in the helper sub-directory.
  • Setup: Some scripts which can generate configuration files plus some SQL files needed for your application.
  • Style: All CSS + Images, can be organised using themes folder.
  • Templates: Divided in two sections. Forms stores all the form templates and layout stores what else layout templates.
  • Tmp: Store temporary files or stuff which is not private. You can use this folder to store cached files in your site as well.
Now the root folder would contain only three files, index.php, config.php and .htaccess. The index.php file acts as a router and translates the GET url to load the particular file. For example consider this URL:
http://yoursite.com/app/index.php?action=login

The index page catches the "action" parameter and loads the login.php file and depending upon the current state plus extra variables performs some action.

Lets get an overview of the index.php file
require_once( DIRNAME(__FILE__) .'/includes/app_init.php');
This line invokes the file which does all the initiation stuff, like loading the configuration file, loading the framework, loading the default template, defining some variables etc.

Tuesday, December 12, 2006

Sphinx mysql fulltext searching

No comments
A few months back i posted about a novel way of indexing data in your MySQL database. There is a small update on this as the developer has launched a dedicated site for that and also includes some API docs and help text. If you are frustrated with MySQL taking forever to index your data i suggest you take a look at this.