Hi,
I'm looking for some opinions of experienced PHP coders.
I have the following situation. In order to learn PHP I decided to code my own Blog software, without any frame work or anything. Every Single line is written by me. I stumbled on a doubt of my design architecture.
I have a page that gets all the Blog entries out of the DB and displays them.
I have a second page that gets all the Comments out of a DB and displays them.
Now after optimizing all of my code I came to the conclusion that bot pages are kind of Identical. So I was wondering what the best way to go is:
Way 1:
index.php
- Lots of Class and variable declaration including my own templating system
- Checking for Nr of posts and making pagination
- Getting all the necessary Blog posts out of DB in while loop.
- During loop setting template variables
comments.php
- Lots of Class and variable declaration including my own templating system
- Checking if user sends info and process it in an object
- Checking for Nr of comments and making pagination
- Getting all the necessary comments out of DB in while loop.
- During loop setting template variables (different ones than blogposts)
Like 70% of the code is the same on both pages.
Way 2:
index.php
- Lots of Class and variable declaration including my own templating system
- if $_GET['action'] == 'comments'
Checking if user sends info and process it in an object
Setting SQL queries for comments
making array with comment template variables
Select comment template
- if $_GET['action'] == entries'
Setting SQL queries for Blog posts
making array with Blog posts template variables
Select blogposts template
- Checking for Nr of to display infos and making pagination
- Getting all the necessary infoss out of DB in while loop.
- During loop setting template variables from the arrays
My Concern is speed vs code redundancy.
If I choose Way 2 the length of the script will increase 60% So in theory it will take longer processing every time the page loads.
In Way 1 only the code needed for particular action is codded in the script so the parser has less work...
On the other Hand, if I find something else to Optimize which is found in both pages I need to change both of them... not really maintenance friendly.
How would the experienced coder look at this?
Thanks for any tips.





)



Bookmarks