Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cakephp Standard - Is it the Proper standard to write things in controller

Sorry for this basic question. The following are the codes presented in my Userscontroller.php

public function register()
{
  //Setting some data
  $this->User->create();
  $this->User->save($this->request->data)
} 

public function edit()
{
  //Setting some data
  $this->User->save($this->request->data)
} 

public function admin_add()
{
  //Setting some data
  $this->User->create();
  $this->User->save($this->request->data)
} 

public function admin_edit()
{
  //Setting some data
  $this->User->save($this->request->data)
} 

One of my senior reviewed this code and said that the above code not met the CAKEPHP Standard..Business logic need to move to model

like as follows in model

<?php 
class User extends AppModel {
  //Validation parts

     public functions savingData($data =array(), $id=false)
    {
       if($id == false)
       {
         $this->create();
       }
       $this->User->save($data)
    }
}?>

And in controllers he is asking to call this savingData function for Create and update options

like image 436
AnNaMaLaI Avatar asked Oct 20 '22 12:10

AnNaMaLaI


1 Answers

in MVC, business rules goes to model.

but in your example there is no any business logic so your code is correct to be in controller.

I suggest to use cakephp console to create controller and model and you can get it by yourself.

like image 172
Mohse Taheri Avatar answered Oct 24 '22 00:10

Mohse Taheri