2006-06-11 3:38 am architecture and php
One of the first things you do when you create a PHP application, is to create a good directory structure.
Many people have their own way of doing things and this is good. The most important thing is that people take the time to think of a good way to do stuff.
Today I'll share mine. I'm not saying this is the best way of doing stuff, this is simply a system that worked well for me.
Here's my main listing:
- lib/
- conf/
- resources/
- index.php
As you can see, I only have 3 directories, each with a specific purpose, and I'm always using a single index.php which handles all the requests.
lib/
This is where my class libraries go. All the classes are in a PEAR-structure, this means: 1 class per file, and the file/directory maps exactly to the classname, for example:the class Services_MetaWebLog can be found in lib/Services/MetaWebLog.php
There are a few good reasons why this is a good way to structure your classes:
- Many systems already use this structure, so if you need foreign libraries (from PEAR, Solar or whatever) you usually can just copy-paste their classes in your structure
- It allows you to easily find certain classes
- It allows a pretty cool __autoload() function
- If you are using subversion, you can easily include other projects libraries with the svn:externals keyword
This is the __autoload function, in case you need it. It's a bit simplified, but you'll get the point.
<?php
function __autoload($classname) {
require_once 'lib/' . str_replace('_', '/', $classname) . '.php';
}
?>
conf/
This is where global application configuration goes. In my case its usually a settings.xml with for example the database DSN.
Another tip is to put you apache configuration here. You can easily create a symlink to your /etc/apache2/sites-enabled . This way you can keep your apache configuration near to your applicaton. If you use Apache1, simply do an Include to this file.
resources/
This is where I put all the static stuff (I guess static would also have been a good name). My sub-directories tend to look like this:
- css/
- templates/
- images/
- js/
- swf/
Good luck!
2006-06-11 2:15 am metaweblog, rsd and webservices
I added a simple implementation of the MetaWeblog API to my blog.. So I could use Flock to post to my blog (in fact, this post is blogged from Flock)
The sad thing is that I have to manually edit the post later on to add the tags.. but other than that, things seem to be working pretty well.
I also updated my services detector to understand relative uri's. Check it out.
Blogged with Flock
I'm currently working on a code section. This is a place where free code can be viewed and downloaded..
The code will either have an open source licence or stuff thats donated to the public domain
Stay tuned..
For FileMobile We have a system that allows people to blog about media they uploaded or stuff they found in the community
To make it easier for people, we want to autodetect the URL to the services, where this is possible. There are different ways to do this. First, for the Atom API there's the services.post in the html header. (http://www.atomenabled.org/developers/api/atom-api-spec.php#Post)
The second method is Really Simple Discovery. A spec for this can be found on: http://media-cyber.law.harvard.edu/blogs/gems/tech/rsd.html.
The latter makes it easy to find API url's for the Blogger, Atom, MetawebLog API and the MovableType api.
Using these systems it can be easy to setup a tool where users can fill in their url, and detect which API they support and how to reach it..
I mocked up a testscript that demonstrates this at: www.rooftopsolutions.nl/blogdetect. So try it out if it works for you. If it doesn't.. drop me a line so I can find out what went wrong. If its working properly i will probably donate it to the open source.
2006-05-29 2:58 am SabreAMF
A simple guideline to install SabreAMF on your computer
First, check if you have all the required software on your machine, basically this is PHP 5 (preferably a recent version) and PEAR.
You can check if you have PEAR installed by running the pear command
If you had bad luck, it might also be outside your default path, for example: if you have php installed on windows in C:\php5 you could try
If PEAR is not installed at all, follow the instructions from:
the pear manual.
Next, download the most recent version of SabreAMF. At the point of writing this is 0.1.1498. The files can be downloaded from http://www.rooftopsolutions.nl/code/?p=SabreAMF&a=d
Now, open op a console (CMD in windows) and go to the path where you downloaded the .tgz file. Then, type in:
pear install SabreAMF-0.1.????.tgz
This should be done with administrator permissions
Thats all!
Update: Updated download link
2006-05-28 10:09 pm general and tags
Today I added a nifty tagcloud below my archives..
Nothing special, and I probably will have to tweak it when more tags are added, but hey.. it's something ;)
I also added a new url scheme for tags, for example:
/tag/general will give you all the posts tagged as 'general'
2006-05-28 5:33 am general
Today I added a commenting system..
It might still need a few tweaks in the design, but so far it seems to work well.
I used a 'math-problem' for a captcha. I realise this is not the definite solution, but as long not many people use a system like this, I'm safe and under the radar)
2006-05-25 6:11 am general
Welcome to my new blog.. There's still a lot that needs to be done, but I hope to publish some updates soon.