Php frameworks

Can you give in laymens terms what the difference is since they both contain functions.

Controllers handle user requests whereas models are associated with business logic. Controllers will generally pass user input as parameters to functions held within models. In the Yii framework a model in the most abstract sense is basically just some functions for validation (e.g. ensuring a user's input for age is an integer..you can also use them for login forms and such). The active record design pattern is very closely associated with models in PHP frameworks. The subtype of an ActiveRecord would represent a database table with an instance of that class representing a row of that database table.

In my example I have a function called create_member() one of these is in the model and takes the information and puts it in a database but I also have a create_member() function that lives in the controller that vadidates the user input ??

The model should be doing the validation, the controller would just set the user input as attributes (properties of the class) then call the model's validate() function.

Also I now have a site that people can login to or sign up to with a members only area. With in the members only area I want to allow them to view records from a database and update them. Is it best to make these as new models and controllers just to separate things out?

Represent each table as a model then house functions within that model for CRUD operations. There'd also be an associated controller for that model to handle the user's request to carry out the CRUD operations.
 
Represent each table as a model then house functions within that model for CRUD operations. There'd also be an associated controller for that model to handle the user's request to carry out the CRUD operations.

You could even go one step further and save yourself a lot of code and use a good base model. A sample one for codeigniter can be found at: https://github.com/jamierumbelow/codeigniter-base-model

It would save you having to write the same CRUD functions for each of your models, as they are essentially the saem code.
 
Back
Top Bottom