What should be done in CodeIgniter models?

I always used the model as something more or less to store and execute database queries. I heard about the fat model, the concept of a thin controller.

The way I customize my models right now causes a lot of undesirable effects in controllers for things like form validation, data formatting. Is form validation, file loading and data formatting supported in the controller or model?

I understand that this question is subjective, which should create a good discussion, and not a specific answer.

+3
source share
3 answers

. / . , , ( ) . psuedo , :

class Controller
{
    function action()
    {
        $input = new Input();
        $form = new FormModel($input);
        if ($errors = $form->errors())
        {
            //load the appropriate view for the errors
        }
        else
        {
            //load the appropriate view for success with an optional redirect
        }
}
+3

. / / . , . . , / lib. , ( ) .

lib . "" ( , ), . , CI CI, . , .

, Vx

+3

A model is what interacts with data (most often with a database). Controllers use models to access data.

0
source

Source: https://habr.com/ru/post/1758657/


All Articles