CakePHP: requests in controller or models?

If I really consider the MVC approach, then the requests should be in the Model, in CakePHP in the table classes, but when I look at the tutorials and documentation that Cake Provides, they simply state that the requests should be in the controller.

As you can see in the example on Cake websites: https://book.cakephp.org/3.0/en/tutorials-and-examples/blog/part-two.html

But if I go through this link or many others that I came across, part of the request should be in the models: https://www.toptal.com/cakephp/most-common-cakephp-mistakes#common-mistake-3-keeping -business-logic-in-controllers-instead-of-models

It's not just about what Cake is demonstrating in the examples or opinions of some developers, but what really should be a genuine way to encode Cake when working with database queries. I found almost 90% of people performing query related tasks in controllers only for Cake, as they quote: "Cake mentions the same thing in its examples." But what about the MVC path, we create table classes to just mention associations? If Cake’s own site does this, for some reason it means that they did it on purpose.

+4
source share
1 answer

, ( ) , , . .

: -

//Consider this code block is in Products Model
function totalActiveProduct(){
   $totalProduct=$this->find('all', ['conditions'=>['is_active'=>'Y']]);
return $totalProduct;
}

, ,

$this->Categories->Products->totalActiveProduct();  //Total procuct in category controller
$this->Products->totalActiveProduct();   //Total products in Product controller.

, , ( , ). , , ( ).

$this->Products->find('all');

, (Where Products - ). .

+3

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


All Articles