使用过滤搜索删除项目的问题

时间:2013-11-12 08:17:17

标签: cakephp search cakephp-2.4

我正在为CakePHP 2开发一个插件。

我的问题如下:

我有一个带过滤搜索的视图,用户可以按类别搜索:

<div>   
<?php echo $this->Form->create('Permission'); ?>
<fieldset>
<?php echo $this->Form->input("permissionCategory", array('label' => 
__d('permission_manager','Categoría'), 'options' => $categorias, 'empty' => 
__d('permission_manager','-- Categorías --'), 'default' => '','class' => 'select-cat', 'onchange' => 'this.form.submit()')); ?>
</fieldset>
<?php //echo $this->Form->end(__d('permission_manager','Aceptar')); ?>
</div>

当我点击删除按钮时,会显示确认消息,但是当我按是时,该项目不会被删除。

我意识到它与行动有关系。也许是请求类型。

行动代码:

public function index() {
  $this->paginate = array('order' => 'Permission.category asc, Permission.code asc');
  $this->Permission->recursive = 2;

  if($this->request->is('post')) {
    if(empty($this->request->data['Permission']['permissionCategory'])) {
      $conditions = null;
    } else {
      $cat = $this->Permission->findById($this->request->data['Permission']
      ['permissionCategory']);
      $conditions = array('Permission.category ' => $cat['Permission']['category']);
    }
    $this->Paginator->settings = array(
    'conditions' => $conditions );    
  }
  $this->set('categorias', $this->Permission->find('list', array('fields' => 'category', 
  'group' => 'category')));
  $this->set('permissions', $this->Paginator->paginate());
}

编辑:

我的删除按钮:

(对于DB中的行,我有一个这样的人)

<?php echo $this->Form->postLink($this->Html->image('PermissionManager.cross.png', 
  array('title' => 
  __d('permission_manager','Borrar'))),'delete/'.h($permission['Permission']['id']), 
  array( 'escape' => false), __d('permission_manager','Are you sure... ?'));
?>

我的删除操作:

public function delete($id = null) {
    $this->Permission->id = $id;
    if (!$this->Permission->exists()) {
        //throw new NotFoundException(__d('permission_manager','Permiso inexistente'));
                    $this->Session->setFlash(__d('permission_manager','Permiso inexistente'), 'default', array('class'=>'error'));
                    return $this->redirect(array('action' => 'index'));
    }
    $this->request->onlyAllow('post', 'delete');
    if ($this->Permission->delete()) {
        $this->Session->setFlash(__d('permission_manager','El permiso ha sido borrado correctamente.'), 'default', array('class'=>'success'));
    } else {
        $this->Session->setFlash(__d('permission_manager','El permiso no ha podido borrarse. Por favor, inténtelo de nuevo.'), 'default', array('class'=>'error'));
    }
    return $this->redirect(array('action' => 'index'));
}

0 个答案:

没有答案