David Turner

Making Decisions & Adapting Plans

Last Semester I spoke about my plans for my Major Project. One of the things I wanted to do was make use of a PHP Framework. I talked about the different options that were available to me, before settling upon Yii.

Over the past few weeks it has become blatantly obvious that trying to pick up the ropes of a PHP Framework isn't something that I should be doing over the course of a single semester, as evidenced by the lack of development being posted on this site of over on ReferenceIt itself. Don't worry though folks, I have a plan.

Two Steps Forward, One Step Back

Sometimes, in order to make progress, a change in direction is needed. I've found this to be the case with the ReferenceIt project this week. As a result I haven't actually made much by the way of progress but I have put myself into a much better position to push forward with my Project.

Those who follow me on twitter may have seen that I have been developing my own flat-file CMS with my spare time. It's what powers this site too and, in a way, has contributed to the mini-framework which will be powering ReferenceIt as I develop it. Both use a very similar structure to their code to determine what needs to be done, and how it should go about doing it.

Naturally a flat-file system won't work particularly well for a dynamic WebApp and, even if it could, I wouldn't dare to try it. The first major difference between this site and the ReferenceIt site is the addition of MySQL, to house content, data and user information. This also helps to ensure that data is as secure as possible, hidden away from the public eye.

URL Logic

Obviously creating a methodology to handle a whole site can be quite problematic but, with a bit of thought, it can be made to be simplistic as well. In Linux based web-servers there is, typically, the ability to rewrite URLs so that what you see in the address bar is human readable, whilst the web server sees something that makes sense to it. Windows based servers use a file called web.config which works differently, but provides the same functionality. In this post I'll be dealing with the platform I use, Linux.

The .htaccess file gives a developer a great deal of flexibility when it comes to web development. I use the functionality it provides in a very basic manner, to redirect everything that isn't a file to my index.php. This is done using the following lines in the .htaccess file:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

This bit of code redirects everything that isn't an actual file, to the index.php file. This allows files which exist to load, whilst redirecting everything to a single file which handles the logic for the site. This allows for easy generation of error pages, as the logic is entirely handled in one place.

Using this I am then able to identify what actions need to be taken based on the URL being used. For example, a URL ending with /references/web/add/ would suggest that I am dealing with references, in particular web references, and that we are wanting to add a reference. Similar structures can be used for print and other forms of references.

Moving Forward

Making the decision to step away from developing using Yii is a risky one. It means that I have wasted some of my time this semester on something which will now be useless in the grand scheme of things. It hasn't been a total waste though, as it has helped me focus on what I need to do, especially with the clock against me.

I'll be looking a bit more in depth at some of the aspects of my progress over the next couple of blog posts on here, as I progress through the aspects of the ReferenceIt site development.