Fuck object oriented PHP. I’m going to do it the procedural way.
Version 2.0 is dead. But not forever. I am starting on version 2.1 first thing in the morning. I had started on the music portion of the site. Specifically the first page of the music section that displayed any news having to do with new songs, new shows, and stuff like that. I wrote the program that got and displayed the information for the page from the database but I couldn’t for the life of me get the program that let me add new information to the database working.
I decided to use an Object Oriented PHP framework called CodeIgniter instead of CakePHP because it was a little easier to understand and implement. I was able to add information to the database using CodeIgniter’s scaffolding feature which basically writes some very basic code that lets you do certain things for you. But I couldn’t use it because its not secure. Any old idiot could find out the directory it was in and edit my site without so much as a password. I’m not running Wikipedia here so in my eyes thats not cool.
I know I eventually need to learn how to use these frameworks because they truly do save you time. But I’m still a newbie to this whole PHP thing. Most PHP frameworks use the object oriented Model View Controller (MVC) approach to programming which is a huge time saver. See, Object Oriented programming whether it be in Java, Ruby, PHP, or whatever breaks up code into manageable chunks. In a very basic general way, this is how it works: You have the code that connects your program to your database seperated from the rest of the code. Then you have the code that performs the application’s functions on its own as well. And finally you have the code that displays the pages to the user somewhere else. This makes updating and upgrading very easy because all you have to do is change the code in one file it applies the changes to the entire site. It also means less code because you only have to write your functions once and reference them using (and I am speaking very generally here) the equivalent of a link or a desktop shortcut/alias to the function in the rest of your code. For example:
This is the seperated function code:
<?php
function nameofFunction() {
it does some stuff that realistically takes up like 10 lines
}
?>
Then You Reference it in another file sort of like this:
$this->get->functionName()
and it does the same thing as the 10 lines of code in the other file. Without this shortcut you’d be rewriting those 10 lines of code multiple times. Now you only have one line of code. And if you ever change the function you don’t need to go and change every reference to it as long as its name hasn’t changed.
But I’m not skilled enough for Object oriented PHP. I have to work the procedural way. The procedural way means writing all the code together and possible multiple times for things like connecting to the database which the application will do multiple times.
So first thing tomorrow morning I will be writing the code for Version 2.1. Its going to be procedural so the code is going to be a bit messy and my view code is going to have to be mixed in with the functionality but once I get the thing working all I need to do is write some CSS and its good to go. This should be a bit easier for me. But Object oriented programming is the way of the future so I will have to upgrade at some point. But not now.
Tags: css, object oriented, Php, program, programming, web, web development