Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Defines the Traditional "Page" Concept in MVC?

I currently use CodeIgniter as my framework of choice when using PHP. One of the things I am wrestling with is the idea of a "page", and how to represent that properly within MVC. To my knowledge, CodeIgniter has a front controller that delegates to page controllers. In my thought process, each page would have it's own controller. All too often though I see someone using a page controller stuffed with many methods. So in that sense, each action becomes it's own page.

I've never really liked the idea of stuffing many methods into one controller, because it seems like there will be too much overhead if you only need one method or two in the controller at a time. It's seems more reasonable for each page to have it's own controller, and the actions would only correspond to something you can do on that particular page. Am I thinking about this the wrong way?

What makes it more confusing is I'll notice in some web applications where they will have one controller that will have multiple methods (i.e. login, register, view, edit, etc.), but then on others they actually have a login controller, and a register controller. What is the proper use of a "page controller"?

like image 655
Joe Avatar asked Apr 17 '09 17:04

Joe


People also ask

What is the page life cycle in MVC?

Actually, there is no concept of page in MVC. So this is not page life cycle but request life cycle.There are seven main steps that happen when you make a request to an Asp.net MVC web applications. 1. Routing Asp.net Routing is the first step in MVC request cycle.

What is master page concept in Vue JS?

Here, we will learn about how to create master page concept in vue.js. Master page concept is also known as theme setup. Its like setting up the pages for layout like sidebar, header, etc. which are common in entire application.

What is master page in ASP NET form?

Earlier in the ASP.NET Web Form there is a concept called master page, so that everything that is common for the website you can put into the master page, or in some cases you can create a Custom User Control for Header, Footer and Left Menu.

How to design MVC project using CSS templates?

Download this simple CSS HTML theme and learn how to design MVC project using this template. Step 1. Start a New Empty MVC 5 Project. Go to File New Project. Select Web in Left side and then Select ASP.NET Web Application as your project. Give the name of your project MVC_Design and click OK.


1 Answers

From a domain perspective I definitely say it makes more sense to have 1 controller per domain context. Not necessarily one per page although depending on the context this may be the case. What I mean by context is "actions that are closely related".

For instance an account controller should handle the login, register, logout, change password, actions. They all live within the context of an "Account"

Take Stackoverflow for example. I would have a "Questions" controller which would have actions like DisplayQuestion, AskQuestion, Delete Question, MostRecent Questions, etc. They are all different "Views/pages" that are managed by one controller.

like image 196
Micah Avatar answered Oct 10 '22 11:10

Micah