PR

CakePHP – ACL再入門(5)

やっぱりACLは難しい。整理の意味も含めてもう一度入門しておく。(今回はCakePHP1.3.2です)

次にgroupsコントローラー。

スポンサードリンク

controllers/groups_controller.php

<?php
class GroupsController extends AppController {

 var $name = 'Groups';
 var $helpers = array('Html', 'Form');
 var $component = array('Session');

 function beforeFilter() {
     parent::beforeFilter();
     //$this->Auth->allowedActions = array('*');
     //$this->Auth->allow = array('*');
 }

 function index() {
  $this->Group->recursive = 0;
  $this->set('groups', $this->paginate());
 }

 function view($id = null) {
  if (!$id) {
   $this->Session->setFlash(__('Invalid Group.', true));
   $this->redirect(array('action'=>'index'));
  }
  $this->set('group', $this->Group->read(null, $id));
 }

 function add() {
  if (!empty($this->data)) {
   $this->Group->create();
   if ($this->Group->save($this->data)) {
    $this->Session->setFlash(__('The Group has been saved', true));
    $this->redirect(array('action'=>'index'));
   } else {
    $this->Session->setFlash(__('The Group could not be saved. Please, try again.', true));
   }
  }
 }

 function edit($id = null) {
  if (!$id && empty($this->data)) {
   $this->Session->setFlash(__('Invalid Group', true));
   $this->redirect(array('action'=>'index'));
  }
  if (!empty($this->data)) {
   if ($this->Group->save($this->data)) {
    $this->Session->setFlash(__('The Group has been saved', true));
    $this->redirect(array('action'=>'index'));
   } else {
    $this->Session->setFlash(__('The Group could not be saved. Please, try again.', true));
   }
  }
  if (empty($this->data)) {
   $this->data = $this->Group->read(null, $id);
  }
 }

 function delete($id = null) {
  if (!$id) {
   $this->Session->setFlash(__('Invalid id for Group', true));
   $this->redirect(array('action'=>'index'));
  }
  if ($this->Group->delete($id)) {
   $this->Session->setFlash(__('Group deleted', true));
   $this->redirect(array('action'=>'index'));
  }
 }

}
?>

コメント

タイトルとURLをコピーしました