vsanse / hackathon

Hackthon PHP Project
http://collabme.tk
0 stars 0 forks source link

New Project Structure #2

Open saxena-aditya opened 6 years ago

saxena-aditya commented 6 years ago

This is just a Suggestion!

Present Stage

So as of now, we have done the following:

and some other small things.

Basic Work-Flow

There are specific .php files that are used to perform activities listed above. For example - for the login action, the user sees login.php file to log in. The URL will be - https://site.com/login.php
What I think is, that this .php at the end of URL is very ugly. URLs should be pretty! like https://site.com/login & https://site.com/register etc etc.

Solution: Pseudo MVC pattern in PHP

I came across an awesome thing some time ago. You guys must have heard of it. What we do is - we catch the URL and break it. For example - suppose the URL is https://site.com/login, the PHP script will take the URL and break it into pieces, it can then form an array that'll have '/' separated string values, 'site.com' and 'login' in this case. We then deploy a switch statement to check for the value.. and then run the required function from there.


$page_url = explode('/', $_SERVER['REQUEST_URI']);
    $script_url = explode('/', $_SERVER['SCRIPT_NAME']);

    for ($x = 0 ; $x < sizeof($page_url) ; $x++)
        if (isset($script_url[$x])) 
         if ($page_url[$x] == $script_url[$x])
               unset($page_url[$x]);

    $values = array_values($page_url);

    // $values[0] -> login
    switch($values[0]) {
        case 'login':
            //show login page.
        break;
        case 'register':
        //show register page.
        break;
        case 'profile':
            //show profile
        break;
        default:
            //show page not found error.
        break;
    }

This script will break the URL into an array named $values. This array contains URL values exploded @ /

Pros:

Cons:

vsanse commented 6 years ago

If we do start over what all sections can be reused? Can we reuse HTML code?

saxena-aditya commented 6 years ago

Yes. We can use almost all the existing HTML code. Only Back-End needs to be updated, and a new AND improved database model will need to be created.

vsanse commented 6 years ago

So let's first design the skeleton of back-end and then start working on it.

On 09-Feb-2018 5:17 PM, "Aditya Saxena" notifications@github.com wrote:

Yes. We can use almost all the existing HTML code. Only Back-End needs to be updated.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Vishu-Chaudhary/hackathon/issues/2#issuecomment-364412916, or mute the thread https://github.com/notifications/unsubscribe-auth/ANZ8LD7mjZCKNxRyLTmL9V84PHa-pKAiks5tTDBogaJpZM4R-h7V .