Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8188297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:51:40+00:00 2026-06-07T02:51:40+00:00

I am creating a website using the MVC structure. Below is a code I

  • 0

I am creating a website using the MVC structure. Below is a code I have used to use clean URLS and load the appropriate files. However it only works for the first level.

Say I wanted to visit mywebsite.com/admin it would work, however mywebsite.com/admin/dashboard would not. The problem is in the arrays, how could I get the array to load content after the 2nd level along with the second level.

Would it be best to create an array like this?

Array
     - controller
     - view
          - dashboard

Any help here would be great. Also as a side question. What would be the best way to set up “custom” urls. So if I were to put in mywebsite.com/announcement it would check to see if its got controllers, failing that, check to see if it’s got custom content (maybe a file of the same name in “customs” folder, and then if there’s nothing execute the 404 page not found stuff) This isn’t a priority question though, but loosely associated in how the code works so I thought it best to add.

function hook() {
    $params = parse_params();
    $url = $_SERVER['REQUEST_URI'];
    $url = str_replace('?'.$_SERVER['QUERY_STRING'], '', $url);

    $urlArray = array();
    $urlArray = explode("/",$url);
    var_dump($urlArray);
    if (isset($urlArray[2]) & !empty($urlArray[2])) {
        $route['controller'] = $urlArray[2];
    } else {
        $route['controller'] = 'front'; // Default Action
    }
    if (isset($urlArray[3]) & !empty($urlArray[3])) {
        $route['view'] = $urlArray[3];
    } else {
        $route['view'] = 'index'; // Default Action
    }
    include(CONTROLLER_PATH.$route['controller'].'.php');
    include(VIEW_PATH.$route['controller'].DS.$route['view'].'.php');
    var_dump($route['controller']);
    var_dump($route['view']);
    var_dump($urlArray);
    var_dump($params);

    // reseting messages
    $_SESSION['flash']['notice'] = '';
    $_SESSION['flash']['warning'] = '';
}
// Return form array
function parse_params() {
    $params = array();
    if(!empty($_POST)) {
        $params = array_merge($params, $_POST);
    }
    if(!empty($_GET)) {
        $params = array_merge($params, $_GET);
    }
    return $params;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:51:42+00:00Added an answer on June 7, 2026 at 2:51 am

    Can you clarify this: “The problem is in the arrays, how could I get the array to load content after the 2nd level along with the second level.”

    I don’t understand how you want this thing to work. I checked your code and it works. Maybe you just need to put $urlArray[1] instead of $urlArray[2] and 2 instead of 3? First element in the array is at index 0.

    Usually it’s done like this:

    Url format:

    /controller/action/param1/param2/...
    
    -controller- should be a class. That class has a method/function called -action-.
    
    ex. /shoes/show/121/   --> this will load controller shoes 
                               and execute the method/function show(121)
                               that will show the shoes that have the id 121 in the
                               database.
    
    ex. /shoes/list/sport  --> this will load controller shoes
                               and execute function list('sport') that will list all
                               shoes in the sport category.
    

    As you can see, you only load one controller and from that controller you run only one function and that function will get the rest of the path and use it as parameters.

    If you want to have multiple controllers for one URL, then the rest of the controllers will have to be loaded from the main controller. Most MVCs (like CodeIgniter) load only one controller per URL.

    Second question:

    Best way for pretty urls would be to save them in the db. This means you can have URLs like this:

    /I-can-write-anything-here-No-need-to-add-ids-or-controller-names
    

    Then you take this URL and search it in db and get the -controller- and -action- that you need for this URL.

    But I have yet to see a popular MVC framework do this. I guess the reason is that the db will get a lot of queries for text matches and that will slow things down.

    Popular MVC frameworks use:

    /controller/action/param1/param2
    

    This has the benefit that you can directly find the controller/action from the url.
    The downside is that you will get urls like:

    /shoes/list/sport 
    //when what you really want is
    /shoes/sport 
    //or just
    /sport //if the website only sells shoes
    

    This can be fixed by redirecting /shoes/sport to /shoes/list/sport

    If you make your own MVC then you should use OOP because if not, thing will get ugly quick: all actions/functions are in the same namespace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a website using MVC framework (Yii) and I need to dynamically create
I am in the process of creating a website using ASP.NET MVC. I went
Summary: I have an ASP.NET MVC website in IIS named 'Website' using an AppPool
I am creating a website using JavaScript/ASP.NET/C#/CSS/HTML/Compact SQL server. I have the majority of
I am creating a website using Java servlets, and I have a page called
I have an existing website developped using ASP.NET MVC 3 and Entity Framework 4
I'm creating an API for a website. I'm using ASP.Net MVC 3 and I'm
I am creating a website using asp.net mvc model. When you create an mvc
After creating a mvc 3 web site using code first & adding same date
I am creating a website using Java EE. I have created a table in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.