How to properly design a PHP website (Quaddicted)?

Discuss programming topics for any language, any source base. If it is programming related but doesn't fit in one of the below categories, it goes here.
Post Reply
Spirit
Posts: 1065
Joined: Sat Nov 20, 2004 9:00 pm
Contact:

How to properly design a PHP website (Quaddicted)?

Post by Spirit »

Some day(tm) I want to rewrite the map database system of Quaddicted, https://www.quaddicted.com/reviews/

What stops me from doing it is that a) right now it is the worst kind of spaghetti as I was learning as I was going and b) I have no idea how to properly design it program-wise.

I have a script that handles the single map view: https://github.com/SpiritQuaddicted/Qua ... etails.php -> (webserver turns *.html into details.php?map=*) -> https://www.quaddicted.com/reviews/sksp2b.html

On it you see some static stuff pulled from the database like the map's title, author, etc. But there are also dynamic parts. Users can add comments and tags to it using a POST to the same script (so I have a huge ifthisifthat block at the head of the file). Users can also rate the map with a GET request to a different php script via AJAX.

User authentication is handled through the cookies of a FluxBB installation which just increases the mess.

I am not using functions nor MVC because I have no clue how. :(

Earlier I wanted to implement user defined lists of maps (eg "maps i have played" or "worst maps evar!!1"). I started drafting some functions (for example addMapToList() that would take the map id and the list id and do the SQL) but gave up when I realised it would just increase the current mess.

Ideally I guess I would have just a bunch of functions like addTag($map, $tag), editComment($id, $newtext) which I could then use without having my scripts explode with SQL here and sanitation there. But then where would I do the authentication for example? Would I have one main script like a main function that handles all requests? How do I do messages after users interacted with the site?

I did look into frameworks once but that just confused me more. :(
Improve Quaddicted, send me a pull request: https://github.com/SpiritQuaddicted/Quaddicted-reviews
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: How to properly design a PHP website (Quaddicted)?

Post by qbism »

Maybe find similar open-source php scripts to examine. Something like hotel or movie reviews? The live filtering of the maplist is unique and I can't think of anything like it. lvl is the first other map review site that comes to mind but it does not have the compact map spreadsheet with sort and filter options.
Spirit
Posts: 1065
Joined: Sat Nov 20, 2004 9:00 pm
Contact:

Re: How to properly design a PHP website (Quaddicted)?

Post by Spirit »

I am a bit afraid those sites' codes would just overwhelm me plus I would not be able to see if they were insane like me or actually well designed.

The big table is something very important to me. I started making some fancy paginated version once but stopped when I realised it would be pointless without order options and selections (by author, year, tags etc):
https://www.quaddicted.com/reviews/notsexyindex2.php
https://www.quaddicted.com/reviews/notsexyindex3.php
https://www.quaddicted.com/reviews/notsexyindex4.php

The live filtering is just client-side JS. I found it somewhere on the internet once. You can see I have no clue how it works (in depth) as I duplicated the code twice for different scenarios. :P
Improve Quaddicted, send me a pull request: https://github.com/SpiritQuaddicted/Quaddicted-reviews
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: How to properly design a PHP website (Quaddicted)?

Post by JasonX »

Use Symfony: http://symfony.com/
Spirit
Posts: 1065
Joined: Sat Nov 20, 2004 9:00 pm
Contact:

Re: How to properly design a PHP website (Quaddicted)?

Post by Spirit »

That's completely overwhelming. Could you say why specifically symfony and how I would plan it?
Improve Quaddicted, send me a pull request: https://github.com/SpiritQuaddicted/Quaddicted-reviews
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: How to properly design a PHP website (Quaddicted)?

Post by JasonX »

Spirit wrote:That's completely overwhelming. Could you say why specifically symfony and how I would plan it?
Well, Symfony allows you to quickly scaffold the website and let's you focus on what really matters: the logic. You can use Doctrine, a PHP ORM, to create your database model (Post entity, Comment entity, glue them together with annotations like @OneToOne, @OneToMany, etc) and then use Symfony's tools to scaffold a CRUD so you can easily admin your website. Also, the same generated code allow you to create the website itself, with forms and views.

Symfony also has a nice templating language built-in, Twig. The MVC architecture in Symfony is quite clean and easy to understand. Basically, you just have to make a controller, define it's route via annotations (directly on top of the method inside the controller class) and assign a view. Check this for some nice tutorials: http://knpuniversity.com
Post Reply