Kristina
Kristina

Reputation: 592

Where does the "front page" fit in MVC?

I think I get the basic concepts of MVC, but I'm not sure where I should put my "home page"? By that I mean for example the page that would come up if you navigated to stackoverflow.com rather than something like stackoverflow.com/questions which has an obvious controller attached (the "questions" controller).

I have a function which determines what controller to use based on a GET variable, but I'm not quite sure what do do when that variable is missing. I was thinking of adding a define() for like a "default path" but I'm not sure what to use. The main page will fall in a category of pages, but will be its own separte entity. To use stackoverflow as the example, I could route the front page to the 'questions" controller, but don't know what to use as an action. "questions/frontpage" seems like a bad name to me.

Its odd, but I don't see this covered in any MVC tutorial online.

Upvotes: 0

Views: 295

Answers (5)

James Anderson
James Anderson

Reputation: 27478

The default page defaults to "index.html". If you have an "index.html" in your root "www" directory this is the page that will be displayed if there is nothing but the web site address on the request url.

You can tweak the apache config file (not sure about ASP) to make another page or script the default, or, to make index.(php|jsp|*) your default.

Depends on circunstances but I would normally recomend you have a static "index.html" page which contains links to the dynamic parts of your website.

Upvotes: 0

yretuta
yretuta

Reputation: 8091

most MVC frameworks map a controller without an "action" specified to the "index()" function within the controller, some kind of a default behavior.

in Kohana's case, a call to

http://mysite.com

is actually mapped to the "default controller" (specified in a configuration file, you can name the controller however you like) and an "index()" function within the controller.

Upvotes: 1

prodigitalson
prodigitalson

Reputation: 60403

Well it could be anything. U normally use Symfony or Zend and i have a module/controller called default or core and generally speaking the home page is the index action in that module/controller. Then in my routing configuration i specify that as the default route using '/' or whatever as my routing URL.

Upvotes: 0

alex
alex

Reputation: 490423

You would use a home controller, generally.

If you have basic routing set up in a bootstrap type file, just point a blank $_SERVER['REQUEST_URI'] or similar to your home controller.

Upvotes: 3

Dan Grossman
Dan Grossman

Reputation: 52372

Most MVC frameworks have some kind of default route defined for the path '/'. You can call the controller whatever makes sense; if nothing else, then "main" or "default" work fine. I typically call the "front page" of any controller "index".

Upvotes: 0

Related Questions