Skip to content

Instantly share code, notes, and snippets.

@erikfig
Created May 2, 2014 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikfig/76104cab0056933702fd to your computer and use it in GitHub Desktop.
Save erikfig/76104cab0056933702fd to your computer and use it in GitHub Desktop.
How to change status in cakephp - Como trocar status no CakePHP
<?php
class MyModel extends AppModel
{
/*
* Change MyModel to your Model
* Change status to your field in database
* $id is your primary key to registry in database
*
* To use in controller: $this->MyModel->enableDisable($id);
* Or model: $this->enableDisable($id);
*
* Troque MyModel para sua Model
* Troque status pelo seu campo no banco de dados
* $id é a chave primaria do registro no banco de dados
*
* Pra usar chame no controller assim: $this->MyModel->enableDisable($id);
* Ou model: $this->enableDisable($id);
*
* Code by Erik Figueiredo
*
*/
public function enableDisable($id)
{
$data = $this->find(
'first',
array(
'conditions'=>array(
'MyModel.id'=$id
),
'fields'=>array(
'MyModel.status'
)
)
);
switch($data['MyModel']['status']){
case 0:
$data['MyModel']['status']=1;
break;
case 1:
$data['MyModel']['status']=0;
break;
};
$this->data['MyModel']['status']=$data['MyModel']['status'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment