PHP pages With User-generated Content

rward

Senior Member
Joined
Oct 26, 2007
Messages
865
Breaking this into 2 parts so it's not too much at once..

Part 1:

Thor, at some stage you may start to get many endpoints:

http://petfinder.com/dogs
http://petfinder.com/cats
http://petfinder.com/cats/siamese
http://petfinder.com/dogs/pugs
http://petfinder.com/about
http://petfinder.com/faq
etc etc

What you're probably going to want to be using is some form of structured 'router'
A really simple one that could help you is : https://github.com/klein/klein.php

I haven't used it before but I took a quick look over it and it seems to be pretty cool and I think will help you a lot.
It's not tied to a framework so it shouldn't bog you down but it does look to have some nice functionality.
 

rward

Senior Member
Joined
Oct 26, 2007
Messages
865
Part 2:

Routes..

When you visit http://petfinder.com/cats/siamese what your browser is doing is a GET request to the URL. By default, browsers do GET.
When you submit a form then you have the "action" value which you can set to GET or POST.

Routes use a combination of the 'action' (I can't remember the correct name - but GET/POST/etc) and the URL.

You would usually have a route for each combination:
eg. Someone wants to add (create) a new cat, you would do a POST to http://petfinder.com/cats
If someone wanted a list of all cats you would do a GET to http://petfinder.com/cats
If someone wanted a single cat then GET http://petfinder.com/cats/51 (or if you have clever URL rewriting http://petfinder.com/cats/mr-tiddles )

This is standard REST api stuff.

With the library I mentioned above, you can do this using somethign like:

Code:
$klein->respond('GET', '/cats/[i:cat_id]', function ($request) {
    $cat = get_cat_from_db_by_id( $request->cat_id);
   return 'We found your cat -  ' . $cat->name;
});

$klein->respond('GET', '/dogs/[i:dog_id]', function ($request) {
    $dog = get_dog_from_db_by_id( $request->dog_id);
   return 'We found your dog -  ' . $dog->name;
});

$klein->respond('GET', '/about', function ($request) {
   $about_page = get_about_pag();
   return $about_page;
});

You could even mash the first 2 together:
Code:
$klein->respond('GET', '/[i:animal_type]/[i:animal_id]', function ($request) {
    $animal = get_animal_from_db_by_type_and_id($request->animal_type, $request->animal_id);
   return 'We found your animal -  ' . $animal->name;
});

return may not be the correct thing to use - possiblty the $response object is, I haven't looked that deep ..
 
Last edited:

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
Ahhh so routes is where I will end up guess I will need to dive into laravel.

This is for something I'm working on for muscletalk, but urg my brain at times struggle a bit I don't like how phpbb is build to be honest, guess I don't have the "authority/experience" yet to complain, some shait just seem done silly to me.

Anyway guess I'll do laravel an mimic my styling I have on the forum to make it all looks seamless
 

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
Just build it already... nobody gets it right the first time; get used to building experiments and stress test these. Then continually enhance with micro iterations;

Ps. the more you stress about a thing, the less you get done... It' easy to talk about "pies in the sky" and scenarios of "a hammer for every nail" -- but then nothing gets done.

Just mockup a site; stress test the hell out out it, and figure out where you can improve: innovation through iteration
 
Last edited:

rward

Senior Member
Joined
Oct 26, 2007
Messages
865
[)roi(];18375296 said:
Just build it already... nobody gets it right the first time; get used to building experiments and stress test these. Then continually enhance with micro iterations;

Ps. the more you stress about a thing, the less you get done... It' easy to talk about "pies in the sky" and scenarios of "a hammer for every nail" -- but then nothing gets done.

Just mockup a site; stress test the hell out out it, and figure out where you can improve: innovation through iteration

Blammo!!

also:
https://www.quora.com/What-are-the-...u-have-learned-on-your-own-by-years-of-coding
 
Last edited:

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
Use Laravel, Thor.

I am going to, this is for PlatinumW I am figuring out how the forum software works then I will build laraval on top of it since I have a very cool idea but I want to use the users ie you create an account that can be used system wide. ( I will get a professional to do the security and all that i am just toying around on a dev site.

[)roi(];18375296 said:
Just build it already... nobody gets it right the first time; get used to building experiments and stress test these. Then continually enhance with micro iterations;

Ps. the more you stress about a thing, the less you get done... It' easy to talk about "pies in the sky" and scenarios of "a hammer for every nail" -- but then nothing gets done.

Just mockup a site; stress test the hell out out it, and figure out where you can improve: innovation through iteration

As per above

Wow! Nice
 

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
I have made this my desktop background


You are not your code. Criticism of your code isn't a criticism of you.
I prefer this instead:
Programmer's Mantra: "It is by caffeine alone I set my mind in motion. It is by the beans of java that thoughts acquire speed, the hands acquire shakes, the shakes become a warning. It is by caffeine alone I set my mind in motion."
 
Top