What is a Controller ?
Any class which uses 'Controller' as a base class is controller.
controller as the name suggest is one who is responsible for controlling the flow. it means which method should be called when a request comes.
controller does nothing, it just orders others to do the work. when a request comes to controller it will fetch the data from the request and will call the appropriate method of the Model with the request data to get the result.
after getting the result controller will call the View which needs to be shown to user and will order view engine to render the page.
so what controller is doing , just ordering others to do some work.
It behaves like Managers.
Why do we need Controller ?
This a good question that comes to mind .. why do we need to call ? why dont we call we the method of model directly?
answers is we dont want our logic to be exposed to the world. here what controller does, it hides the real business logic and behaves it has everything. so user can never know about real business logic or methods having the business logic and can not call our business logic.
there more responsibilities of controller we will talk about those in another post.
Any class which uses 'Controller' as a base class is controller.
controller as the name suggest is one who is responsible for controlling the flow. it means which method should be called when a request comes.
controller does nothing, it just orders others to do the work. when a request comes to controller it will fetch the data from the request and will call the appropriate method of the Model with the request data to get the result.
after getting the result controller will call the View which needs to be shown to user and will order view engine to render the page.
so what controller is doing , just ordering others to do some work.
It behaves like Managers.
Why do we need Controller ?
This a good question that comes to mind .. why do we need to call ? why dont we call we the method of model directly?
answers is we dont want our logic to be exposed to the world. here what controller does, it hides the real business logic and behaves it has everything. so user can never know about real business logic or methods having the business logic and can not call our business logic.
there more responsibilities of controller we will talk about those in another post.
No comments:
Post a Comment