Hi Guys,
I am Pretty New To Developing in PHP + Laravel, I was recently learning to Code Raw PHP when I decided to Invest in Laravel after reading up on it...
I have made some head way in understanding the Routes and Blades etc... and so forth... However While I somewhat understand MVC I am not 100% clear on it...
From what I have read this is how I interpret it and ask if you would take the time to correct me where I stray of the MVC Path...
First in Understanding the Model, I understand that one creates a Model per Table in the Database,
Inside the Model one will define the Functions that Retrieve the Data from the model in Defined methods
For Example:
we have a table (Users)
so we will create several methods which can be called to get data from the table in controlled ways
- function All_Users ();
- This will return all users from the table
- function get_Users ($id);
- This will return users based on the parameter defined $id
We can Create several functions which will be called from the controller to get the data in several different ways. Including Removing Information etc.
- Like top_ten(), last_entry() etc as required by website... and so on etc.
Second is the Controller, The Controller which is called from the view will then have its CRUD operations or Several Variations of specific CRUD operations that
will call on the methods defined in the model as follows
For Example:
Using the Model Above we will call the model then its method All_Users () as follows
$Users->All_Users();
This will simply Get the data from the model as predefined in the model
As I understand it the Controller is there to communicate between a view and 1 or more models...
Meaning in the case that I had a dashboard and wanted to see the users with the roles and the Permissions I would have a dashboard controller that
makes calls to the models
* Users
* Roles
* Permissions
Then it will pass the information back to the Dashboard view and the view will manipulate the Data and present it in the desired format and design.
The Controller should be as light as possible so it should not manipulate the data which should be the task of the model and should just be passing
requests from the view to the model and the data back to the view from the model
The Controller will have CRUD Methods which will simply define what Models and Methods of the Models should be executed to get the results it needs
and then the results are passed back to the view to be displayed.
(From My Novice Point of View I would create a Controller Per View in the Case where the particular View needs to communicate with the database)
Third is the View, The View is what the user sees, It makes any requests from user input and processes it by making the relevant calls to the Controller and
then or any request without user input manipulates it to present the results to the user to see...
The View never connects directly to the data or the model and always goes via the Controller...
Please provide me with any clarity if my understanding it incorrect... As I am new to MVC, I have been reading about it for some time but this is the first time I am using it. I have read a few books as well but most people who write about MVC or any other assume that anyone who is programming has used it in some form or another before... And this is not the case...
I can easily learn it as i go along but if it don't understand it correctly I might become accustomed to using it the wrong way and then it will be hard to change those ways later on.
I am Pretty New To Developing in PHP + Laravel, I was recently learning to Code Raw PHP when I decided to Invest in Laravel after reading up on it...
I have made some head way in understanding the Routes and Blades etc... and so forth... However While I somewhat understand MVC I am not 100% clear on it...
From what I have read this is how I interpret it and ask if you would take the time to correct me where I stray of the MVC Path...
First in Understanding the Model, I understand that one creates a Model per Table in the Database,
Inside the Model one will define the Functions that Retrieve the Data from the model in Defined methods
For Example:
we have a table (Users)
so we will create several methods which can be called to get data from the table in controlled ways
- function All_Users ();
- This will return all users from the table
- function get_Users ($id);
- This will return users based on the parameter defined $id
We can Create several functions which will be called from the controller to get the data in several different ways. Including Removing Information etc.
- Like top_ten(), last_entry() etc as required by website... and so on etc.
Second is the Controller, The Controller which is called from the view will then have its CRUD operations or Several Variations of specific CRUD operations that
will call on the methods defined in the model as follows
For Example:
Using the Model Above we will call the model then its method All_Users () as follows
$Users->All_Users();
This will simply Get the data from the model as predefined in the model
As I understand it the Controller is there to communicate between a view and 1 or more models...
Meaning in the case that I had a dashboard and wanted to see the users with the roles and the Permissions I would have a dashboard controller that
makes calls to the models
* Users
* Roles
* Permissions
Then it will pass the information back to the Dashboard view and the view will manipulate the Data and present it in the desired format and design.
The Controller should be as light as possible so it should not manipulate the data which should be the task of the model and should just be passing
requests from the view to the model and the data back to the view from the model
The Controller will have CRUD Methods which will simply define what Models and Methods of the Models should be executed to get the results it needs
and then the results are passed back to the view to be displayed.
(From My Novice Point of View I would create a Controller Per View in the Case where the particular View needs to communicate with the database)
Third is the View, The View is what the user sees, It makes any requests from user input and processes it by making the relevant calls to the Controller and
then or any request without user input manipulates it to present the results to the user to see...
The View never connects directly to the data or the model and always goes via the Controller...
Please provide me with any clarity if my understanding it incorrect... As I am new to MVC, I have been reading about it for some time but this is the first time I am using it. I have read a few books as well but most people who write about MVC or any other assume that anyone who is programming has used it in some form or another before... And this is not the case...
I can easily learn it as i go along but if it don't understand it correctly I might become accustomed to using it the wrong way and then it will be hard to change those ways later on.