Advertisement
Guest User

Untitled

a guest
Oct 7th, 2013
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.33 KB | None | 0 0
  1. <?php
  2. class UsersController extends AppController {
  3.  
  4.     public $components = array('RequestHandler');
  5.     public function beforeFilter() {
  6.         parent::beforeFilter();
  7.         // $this->response->header('Access-Control-Allow-Origin', '*');
  8.         $this->RequestHandler->ext = 'json';
  9.     }
  10.  
  11.  
  12.     public function index() {
  13.         $users = $this->User->find('all');
  14.         $this->set(array(
  15.             'users' => $users,
  16.             '_serialize' => array('users')
  17.         ));
  18.     }
  19.  
  20.     public function add() {
  21.         $this->User->create();
  22.         if ($this->User->save($this->request->data)) {
  23.             $message = 'Saved';
  24.         } else {
  25.             $message = 'Error';
  26.         }
  27.         $this->set(array(
  28.             'message' => $message,
  29.             '_serialize' => array('message')
  30.         ));
  31.     }
  32.  
  33.     public function view($id) {
  34.         $user = $this->User->findById($id);
  35.         $this->set(array(
  36.             'user' => $user,
  37.             '_serialize' => array('user')
  38.         ));
  39.     }
  40.  
  41.     public function edit($id) {
  42.         $this->User->id = $id;
  43.         if ($this->User->save($this->request->data)) {
  44.             $message = 'Saved';
  45.         } else {
  46.             $message = 'Error';
  47.         }
  48.         $this->set(array(
  49.             'message' => $message,
  50.             '_serialize' => array('message')
  51.         ));
  52.     }
  53.  
  54.     public function delete($id) {
  55.         if ($this->User->delete($id)) {
  56.             $message = 'Deleted';
  57.         } else {
  58.             $message = 'Error';
  59.         }
  60.         $this->set(array(
  61.             'message' => $message,
  62.             '_serialize' => array('message')
  63.         ));
  64.     }
  65. }
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement