PHP :: MVC All Controller requests through Model?
up vote
0
down vote
favorite
Is it best practice to have all information pass through the MODEL to the CONTROLLER?
For example, I have a controller named "Apps" and a model named "App". I want to show a form with a list of users, which is in the "Users" class in the libraries folder. Can I simply request the list of users from the "Users" class directly from the CONTROLLER or is it best to first go through the MODEL and then to the CONTROLLER?
TIA
php model-view-controller
add a comment |
up vote
0
down vote
favorite
Is it best practice to have all information pass through the MODEL to the CONTROLLER?
For example, I have a controller named "Apps" and a model named "App". I want to show a form with a list of users, which is in the "Users" class in the libraries folder. Can I simply request the list of users from the "Users" class directly from the CONTROLLER or is it best to first go through the MODEL and then to the CONTROLLER?
TIA
php model-view-controller
Controllers are not supposed to pull information from the Model layer. Their responsibility is to alter the state of said layer. The view classes are the ones, that are responsible for gathering the current (or changed) state from the Model layer and populating templates with it.
– tereško
Nov 21 at 11:35
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Is it best practice to have all information pass through the MODEL to the CONTROLLER?
For example, I have a controller named "Apps" and a model named "App". I want to show a form with a list of users, which is in the "Users" class in the libraries folder. Can I simply request the list of users from the "Users" class directly from the CONTROLLER or is it best to first go through the MODEL and then to the CONTROLLER?
TIA
php model-view-controller
Is it best practice to have all information pass through the MODEL to the CONTROLLER?
For example, I have a controller named "Apps" and a model named "App". I want to show a form with a list of users, which is in the "Users" class in the libraries folder. Can I simply request the list of users from the "Users" class directly from the CONTROLLER or is it best to first go through the MODEL and then to the CONTROLLER?
TIA
php model-view-controller
php model-view-controller
asked Nov 21 at 2:00
Derwoody
324
324
Controllers are not supposed to pull information from the Model layer. Their responsibility is to alter the state of said layer. The view classes are the ones, that are responsible for gathering the current (or changed) state from the Model layer and populating templates with it.
– tereško
Nov 21 at 11:35
add a comment |
Controllers are not supposed to pull information from the Model layer. Their responsibility is to alter the state of said layer. The view classes are the ones, that are responsible for gathering the current (or changed) state from the Model layer and populating templates with it.
– tereško
Nov 21 at 11:35
Controllers are not supposed to pull information from the Model layer. Their responsibility is to alter the state of said layer. The view classes are the ones, that are responsible for gathering the current (or changed) state from the Model layer and populating templates with it.
– tereško
Nov 21 at 11:35
Controllers are not supposed to pull information from the Model layer. Their responsibility is to alter the state of said layer. The view classes are the ones, that are responsible for gathering the current (or changed) state from the Model layer and populating templates with it.
– tereško
Nov 21 at 11:35
add a comment |
3 Answers
3
active
oldest
votes
up vote
-1
down vote
The way MVC normally works, is that the View makes a request to the Controller. The Controller then accesses the Model, handles all the business logic and updates the View.
So in your case, the User class could be your Model.
Eg.
- The View requests a list of users
- The Controller handles the request and gets the list of users from the Model (eg. through database)
- The Controller then updates the View with the list or the View has access to the list and renders it.
Here is more information.
add a comment |
up vote
-1
down vote
As you tag your question with php
I can explain in its terms. View(HTML form or AJAX) do request to controller, usually a php file(by post or get request) what processes and redirects requests to (Model)separate php code what work with data(DB), that code returns result to controller and it one to model. Consider using some existing MVC framework what suits your needs.
Model–view–controller is an architectural pattern commonly used for
developing user interfaces that divides an application into three
interconnected parts. This is done to separate internal
representations of information from the ways information is presented
to and accepted from the user. The MVC design pattern decouples these
major components allowing for efficient code reuse and parallel
development.
https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
add a comment |
up vote
-1
down vote
I'm agree your point, but we must consider the size of the project. For example, in one big-size project, I usually command it like controller <=> services <=> models <=> tables.
- Tables: run sql (CURD)
- Models: call tables finish one feature (Like after get article also need update view times)
- Services: call models finish one function (Like payment)
- Controllers: Input/Permissions validator then call service finish it.
Of course, if one simple blog we can do all in controllers.
And same idea for view, may full page, may group components as one page, and component may also has childrens.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
-1
down vote
The way MVC normally works, is that the View makes a request to the Controller. The Controller then accesses the Model, handles all the business logic and updates the View.
So in your case, the User class could be your Model.
Eg.
- The View requests a list of users
- The Controller handles the request and gets the list of users from the Model (eg. through database)
- The Controller then updates the View with the list or the View has access to the list and renders it.
Here is more information.
add a comment |
up vote
-1
down vote
The way MVC normally works, is that the View makes a request to the Controller. The Controller then accesses the Model, handles all the business logic and updates the View.
So in your case, the User class could be your Model.
Eg.
- The View requests a list of users
- The Controller handles the request and gets the list of users from the Model (eg. through database)
- The Controller then updates the View with the list or the View has access to the list and renders it.
Here is more information.
add a comment |
up vote
-1
down vote
up vote
-1
down vote
The way MVC normally works, is that the View makes a request to the Controller. The Controller then accesses the Model, handles all the business logic and updates the View.
So in your case, the User class could be your Model.
Eg.
- The View requests a list of users
- The Controller handles the request and gets the list of users from the Model (eg. through database)
- The Controller then updates the View with the list or the View has access to the list and renders it.
Here is more information.
The way MVC normally works, is that the View makes a request to the Controller. The Controller then accesses the Model, handles all the business logic and updates the View.
So in your case, the User class could be your Model.
Eg.
- The View requests a list of users
- The Controller handles the request and gets the list of users from the Model (eg. through database)
- The Controller then updates the View with the list or the View has access to the list and renders it.
Here is more information.
answered Nov 21 at 2:16
CUGreen
1,7901411
1,7901411
add a comment |
add a comment |
up vote
-1
down vote
As you tag your question with php
I can explain in its terms. View(HTML form or AJAX) do request to controller, usually a php file(by post or get request) what processes and redirects requests to (Model)separate php code what work with data(DB), that code returns result to controller and it one to model. Consider using some existing MVC framework what suits your needs.
Model–view–controller is an architectural pattern commonly used for
developing user interfaces that divides an application into three
interconnected parts. This is done to separate internal
representations of information from the ways information is presented
to and accepted from the user. The MVC design pattern decouples these
major components allowing for efficient code reuse and parallel
development.
https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
add a comment |
up vote
-1
down vote
As you tag your question with php
I can explain in its terms. View(HTML form or AJAX) do request to controller, usually a php file(by post or get request) what processes and redirects requests to (Model)separate php code what work with data(DB), that code returns result to controller and it one to model. Consider using some existing MVC framework what suits your needs.
Model–view–controller is an architectural pattern commonly used for
developing user interfaces that divides an application into three
interconnected parts. This is done to separate internal
representations of information from the ways information is presented
to and accepted from the user. The MVC design pattern decouples these
major components allowing for efficient code reuse and parallel
development.
https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
add a comment |
up vote
-1
down vote
up vote
-1
down vote
As you tag your question with php
I can explain in its terms. View(HTML form or AJAX) do request to controller, usually a php file(by post or get request) what processes and redirects requests to (Model)separate php code what work with data(DB), that code returns result to controller and it one to model. Consider using some existing MVC framework what suits your needs.
Model–view–controller is an architectural pattern commonly used for
developing user interfaces that divides an application into three
interconnected parts. This is done to separate internal
representations of information from the ways information is presented
to and accepted from the user. The MVC design pattern decouples these
major components allowing for efficient code reuse and parallel
development.
https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
As you tag your question with php
I can explain in its terms. View(HTML form or AJAX) do request to controller, usually a php file(by post or get request) what processes and redirects requests to (Model)separate php code what work with data(DB), that code returns result to controller and it one to model. Consider using some existing MVC framework what suits your needs.
Model–view–controller is an architectural pattern commonly used for
developing user interfaces that divides an application into three
interconnected parts. This is done to separate internal
representations of information from the ways information is presented
to and accepted from the user. The MVC design pattern decouples these
major components allowing for efficient code reuse and parallel
development.
https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
answered Nov 21 at 2:19
LeonidMew
1429
1429
add a comment |
add a comment |
up vote
-1
down vote
I'm agree your point, but we must consider the size of the project. For example, in one big-size project, I usually command it like controller <=> services <=> models <=> tables.
- Tables: run sql (CURD)
- Models: call tables finish one feature (Like after get article also need update view times)
- Services: call models finish one function (Like payment)
- Controllers: Input/Permissions validator then call service finish it.
Of course, if one simple blog we can do all in controllers.
And same idea for view, may full page, may group components as one page, and component may also has childrens.
add a comment |
up vote
-1
down vote
I'm agree your point, but we must consider the size of the project. For example, in one big-size project, I usually command it like controller <=> services <=> models <=> tables.
- Tables: run sql (CURD)
- Models: call tables finish one feature (Like after get article also need update view times)
- Services: call models finish one function (Like payment)
- Controllers: Input/Permissions validator then call service finish it.
Of course, if one simple blog we can do all in controllers.
And same idea for view, may full page, may group components as one page, and component may also has childrens.
add a comment |
up vote
-1
down vote
up vote
-1
down vote
I'm agree your point, but we must consider the size of the project. For example, in one big-size project, I usually command it like controller <=> services <=> models <=> tables.
- Tables: run sql (CURD)
- Models: call tables finish one feature (Like after get article also need update view times)
- Services: call models finish one function (Like payment)
- Controllers: Input/Permissions validator then call service finish it.
Of course, if one simple blog we can do all in controllers.
And same idea for view, may full page, may group components as one page, and component may also has childrens.
I'm agree your point, but we must consider the size of the project. For example, in one big-size project, I usually command it like controller <=> services <=> models <=> tables.
- Tables: run sql (CURD)
- Models: call tables finish one feature (Like after get article also need update view times)
- Services: call models finish one function (Like payment)
- Controllers: Input/Permissions validator then call service finish it.
Of course, if one simple blog we can do all in controllers.
And same idea for view, may full page, may group components as one page, and component may also has childrens.
answered Nov 21 at 3:25
incNick
1794
1794
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404312%2fphp-mvc-all-controller-requests-through-model%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Controllers are not supposed to pull information from the Model layer. Their responsibility is to alter the state of said layer. The view classes are the ones, that are responsible for gathering the current (or changed) state from the Model layer and populating templates with it.
– tereško
Nov 21 at 11:35