Workin' on the railroad. Or somethin'.

Nov 03, 2008 18:31

Ok, so maybe not the railroad, but I have been working on my site over at http://www.runicsystems.com. Almost got the back end finished now. Mostly just lacking the mechanism that lets users go from viewing a description of the programs to actually being able to download them. That shouldn't be too hard, though.

This architecture is so nice, though. I went with an MVC-like design that makes it a snap to add new pages to the site. I made a very simple templating engine that will replace key-words inside braces with an @ symbol with the values that I pass it from the controller class. Currently the view section of my design is very, very modularized. When I started making the view section, I had several pieces of the site that I knew were going to be re-used repeatedly (like the HTML for a news post). However, since my templating engine is not sophisticated enough to allow me to put PHP into it (it was something I sort of wanted to avoid, anyway), I ended up having the controllers do the replication of those chunks. So, I take the template for the news post, read it into a for loop inside the controller, and then fill in the values for the news post template for each news object and stick them all together. At that point I take the output from all of those and put it into the content value of a larger component, whose output is then put inside the content value of my layout.

It's probably a little more complicated than it needs to be-- I think I probably compartmentalized the individual parts of the site (e.g. news posts) a little too much, but it's still a whole lot better than my previous design pattern.

Another nice feature of the site, is I have a single index page that processes all the requests going into the site. So now, instead of needing to have a shared header (that starts the sessions, checks for saved logins, handles new logins, and loads up the stylesheet and banner and things) that I have to include on every single page of the site, I just have 1 page that does the PHP stuff, and an HTML layout that handles all the other stuff. This really allows me to take advantage of the object-oriented approach of PHP. The index page forwards to a single controller, called the PageController which looks at what was requested in the address bar, then loads up the controller for that page request and tells it to load the page and give back the results. Bam. No more worrying about how to redirect before I get output sent to the browser.

If I want to redirect, I can-- no problems, as output is only given to the browser in one spot-- back in the index page after all the processing is complete-- or I can usually just tell some other controller function to give its output instead, without having to bother with a redirect, which can be slow.

The PageController just looks in the database to see what request belongs with which controller. So, if I want to add a new page, all I have to do is write up the controller for it, code up its view, and then go and put the new request name in the database with the controller that handles it, and bam. None of the other code needs to be changed.

I'm also using prepared statements and MySQLi on this particular website. I have to say, it's a lot nicer than the other, standard PHP MySQL functions. This way I don't have to do much worrying about escaping the user input with the big, ugly mysql_real_escape_string() function. Let me tell you, it gets to be a real pain to type that an average of 3 times for every query you write. The prepared statements handle escaping the input for me! Plus they allow me to further make use of the object-oriented paradigm, which is a lot nicer than having to pass around 7 or 8 different variables every time I want to send an object to a new function-- the OO approach allows me to send just 1 object, and sometimes I don't need to send any at all because they're class variables.

I'm also really happy with the way the site design turned out from the user perspective. I think it's aesthetically pleasing, and pretty easy to use and navigate. Very happy with the way things are going with it. After I get done finishing up the back end of the site, it'll be time to make some finishing touches on a couple of the programs I've been working on, then put them up there for download.


programming, technology, website

Previous post Next post
Up