Created
May 2, 2014 13:16
-
-
Save erikfig/76104cab0056933702fd to your computer and use it in GitHub Desktop.
How to change status in cakephp - Como trocar status no CakePHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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