Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 删除不工作的用户_Php_Sql_Cakephp - Fatal编程技术网

Php 删除不工作的用户

Php 删除不工作的用户,php,sql,cakephp,Php,Sql,Cakephp,我希望能够删除一个用户,但当我尝试删除时,它会抛出以下错误。错误:在此服务器上找不到请求的地址“/cakephp/users/delete/8?url=users%2Fdelete%2F8” 我的删除函数的代码是 public function delete($id = null) { debug($this->User->delete()); if (!$this->request->is('get')) {

我希望能够删除一个用户,但当我尝试删除时,它会抛出以下错误。错误:在此服务器上找不到请求的地址“/cakephp/users/delete/8?url=users%2Fdelete%2F8”

我的删除函数的代码是

public function delete($id = null)
{
        debug($this->User->delete());
        if (!$this->request->is('get')) 
        {
             throw new MethodNotAllowedException();
        }
        if ($this->User->delete($id)) 
        {
            $this->Session->setFlash('The user with id: ' . $id . ' has been deleted.');
            $this->redirect(array('action' => 'usermanage'));
        }
  }
[新] 我去掉了用户管理代码和索引代码,为我的用户模型代码腾出了空间

<?php
App::uses('AuthComponent', 'Controller/Component');
class User extends AppModel {

    public $primary_key = 'userID';
    public $validate = array(
        'username' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'A username is required'
            )
        ),

        'password' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'A password is required'
            )
        ),
        'name' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'Your name is required'
            )
        ),
        'surname' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'Your surname is required'
            )
        ),
        'memberType' => array(
            'valid' => array(
                'rule' => array('inList', array('admin', 'responder', 'volunteer')),
                'message' => 'Please enter a valid role',
                'allowEmpty' => false
            )
        ),
        'address1' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'Please enter your first line of address'
            )
        ),
        'address2' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'please enter your second line of address'
            )
        ),
        'town' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'Please enter your town'
            )
        ),
        'postCode' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'please enter your postcode'
            )
        ),
        'dob' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'please enter your date of birth'
            )
        ),
        'emailAddress' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'please enter your email address'
            )
        ),
        'phoneNumber' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'please enter your phone number'
            )
        ),
        'mobileNumber' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'please enter your mobile number'
            )
        )
    );

    public function beforeSave($options = array()) {
        if (isset($this->data[$this->alias]['password'])) {
            $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
        }
    }
}
?>


任何帮助都将不胜感激

此错误可通过两种方式更正(第一种):

1-将删除操作更改为:

if (!$this->request->is('post') && !$this->request->is('put')) {
    throw new MethodNotAllowedException();
}
2-不使用postLink,并更改删除操作:

<?php echo $this->Html->link('Delete', array('controller' => 'users', 'action' => 'delete', $user['User']['userID'])); ?>

public function delete($id = null) {
        $this->User->id = $id;

        if(!$this->User->exists()) {
            throw new NotFoundException(__('Invalid user'));
        }

        if ($this->User->delete($id)) {
            $this->Session->setFlash('The user with id: ' . $id . ' has been deleted.');
            $this->redirect(array('action' => 'usermanage'));
        }
}
在其他型号中(belongsTo、hasMany、hasblongstomany):


对不起,我的英语很差,我是巴西人。

请将相关路线添加到您的帖子中。其他操作(如编辑和查看)是否有效?编辑功能也不起作用,我为该功能创建了一个问题,但只有不成功的答案:(我现在添加了索引页(将用户引导到用户管理页)
/cakephp
您是文档根目录吗?是的,/cakephp是我文档的根目录,但是您遇到了另一个问题。您的htaccess设置可能无效。因此它会重定向到或显示/?url=而不是/?查看htaccess的正确2.x设置Hello Patrick,谢谢您的回答,我想我已经做了一些专业设置gress…但我现在唯一的问题是sql语句似乎认为我的用户ID称为“ID”而不是“userID”,我如何解决这个问题?你需要为该模型设置正确的主键。@patrick和noslone,我现在已将主键添加到用户模型中,但它仍在尝试查找“ID”作为主键..解决了它,它应该是$primaryKey而不是$primary_key..耶,谢谢Patrick和Noslone!!!
public $primary_key = 'userID';
public $belongsTo = array(
    'User' => array(
        'className'    => 'User',
        'foreignKey'   => 'userID'
    )
);