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

  • Home
  • SEARCH
  • 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 3428170
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:55:36+00:00 2026-05-18T06:55:36+00:00

All, I am studying some sample code given in my web dev class as

  • 0

All,

I am studying some sample code given in my web dev class as an example of MVC (again, for the web). In this code, there’s a system to navigate from the index.php page to the various controllers (which then call the Model and View modules), and then back into index.php.

I understand how the MVC works.

What I’m grappling with is the navigation mechanism. I am having difficulties understanding how all the pieces work together.

Could anyone take a look at the code below and tell me if this matches a well known method / pattern to deal with dynamic website navigation? (Maybe the Front Controller?) If it does, then my hope is that I can more easily do some more research on it.

Many thanks!

JDelage

Index.php

<?php
require_once("User.php");
session_start();

if (isset($_GET['action'])) 
  $action= $_GET['action'];
 else
   $action="";

switch ($action) {
 case 'login':
   require_once('Login.php');
   $command= new LoginControler();
   break;
 case 'logoff':
   require_once('Logoff.php');
   $command= new LogoffControler();
   break;
// Several other cases
 default:
   require_once('Unknown.php');
   $command= new UnknownControle();
}


$command->execute();
require_once('EntryMenu.php'); // Those are objects that represent both the 
// menu label and the links.
$menu= array(
         new EntryMenu("Login", "index.php", array("action" => "logon")),
         new EntryMenu("Logoff", "index.php", array("action" => "logoff")),
         new EntryMenu("Write", "index.php", array("action" => "write")),
         new EntryMenu("Read", "index.php", array("action" => "read"))
);

if ($command->redirect) {
  header('Location: ' . $command->redirect);
 } else if ($command->page) {

  include("ui/header.php");
  include("ui/menu.php");
  echo "<div class='content'>";
  include("ui/". $command->page);
  echo "</div>";
  include("ui/footer.php");
 }
?>

Controler.php

<?php
class Controler {
    public $page= "problem.php";
    function execute() {}
}
?>

LogoffControler.php

<?php
require_once('Controler.php');
class LogoffControler extends Controler {

  function execute() {
    $this->redirect= "index.php";
    unset($_SESSION['user']);
  } 
}
?>

LoginControler.php

<?php
 require_once('LoginModel.php'); // This manages the exchanges with the user db
 require_once('Controler.php');

 class ConnexionControle extends Controler {
  public $page= "LoginForm.php";

  function execute() {

  // More code to deal with incorrectly filled login forms

  $login = new LoginModel();
  $login->loginUser($_POST['login'], $_POST['password']);
  if ($login->userLogedIn()) {
    $_SESSION['user']= $login->user;
    $this->redirect= "index.php";
  }

// More code to deal with invalid logins

 } 
}
?>
  • 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-05-18T06:55:37+00:00Added an answer on May 18, 2026 at 6:55 am

    I am assuming you understand the controller part, and is asking about the switch..case statements. I haven’t come across an official name for that yet,but most MVC frameworks for PHP (Kohana, CakePHP, CodeIgniter, Fat Free and etc.) calls that ‘routing’. It’s mapping of a URL to a controller.

    Using a switch..case sets of statement is one of the easier ways. More sophisticated solutions use RegEx to match pre-defined URL patterns to resolve what controller to invoke, and what are its parameters (usually bundled as a ‘request’)

    Other methods include using URL rewriting to come up with pretty urls, such as /articles/month/nov/article-id/3

    which in ‘ugly url form’ is :

    action=articles&month=nov&article-id=3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In class, we are all 'studying' databases, and everyone is using Access. Bored with
All I want is to update an ListViewItem's text whithout seeing any flickering. This
All too often I want a WPF slider that behaves like the System.Windows.Forms.TrackBar of
I have been studying .NET 4.0 Code Contracts and looking on stackoverflow as well
i am self-studying asp.net and was trying some small projects to help understand the
I'm studying the mtl library and trying to do some MonadTransformers of my own.
All the articles I've found via google are either obsolete or contradict one another.
All the recent VisualSVN Server posts made me want to check it out. I
All front-end developers know the pain of coding for Firefox, then viewing our then
All I know about the constraint is it's name ( SYS_C003415 ), but I

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.