Page 1 of 1

How to properly design a PHP website (Quaddicted)?

Posted: Sun Feb 09, 2014 3:46 pm
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. :(

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

Posted: Thu Feb 13, 2014 2:52 am
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.

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

Posted: Thu Feb 13, 2014 4:07 pm
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

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

Posted: Thu Feb 13, 2014 9:45 pm
by JasonX
Use Symfony: http://symfony.com/

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

Posted: Fri Feb 14, 2014 6:41 pm
by Spirit
That's completely overwhelming. Could you say why specifically symfony and how I would plan it?

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

Posted: Mon Feb 17, 2014 8:53 pm
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