Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.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
cakePHP注册don';行不通_Php_Cakephp_Cakephp 3.0 - Fatal编程技术网

cakePHP注册don';行不通

cakePHP注册don';行不通,php,cakephp,cakephp-3.0,Php,Cakephp,Cakephp 3.0,我是CakePHP新手,只是从烹饪书的例子开始。现在我想用我的custome表列创建一个简单的注册和登录表单。但是系统不想插入数据!我的错在哪里?在AppController中告诉他要使用哪些字段对吗 add.ctp= <div class="users_form"> <?= $this->Form->create($user) ?> <fieldset> <legend><?= __('Add') ?></l

我是CakePHP新手,只是从烹饪书的例子开始。现在我想用我的custome表列创建一个简单的注册和登录表单。但是系统不想插入数据!我的错在哪里?在AppController中告诉他要使用哪些字段对吗

add.ctp=

<div class="users_form">
<?= $this->Form->create($user) ?>
<fieldset>
    <legend><?= __('Add') ?></legend>
    <?= $this->Form->input('username') ?>
    <?= $this->Form->input('password') ?>

</fieldset>
<?= $this->Form->button(__('Submit')); ?>
<?= $this->Form->end() ?>
AppController.php

 parent::initialize();

    $this->loadComponent('RequestHandler');
    $this->loadComponent('Flash');
     $this->loadComponent('Auth', [
    'authenticate' => [
        'Form' => [
            'fields' => ['username' => 'ab_mail', 'password' => 'ab_pass']
        ]
    ]
]);
 public function add()
{
    $user = $this->Users->newEntity();
    if ($this->request->is('post'))
    {
        $user = $this->Users->patchEntity($user, $this->request->data);
        if ($this->Users->save($user)) 
        {
            $this->Flash->success(__('inserted!'));
            return $this->redirect(['action' => 'add']);
        }
        $this->Flash->error(__('Error!'));
    }
    $this->set('user', $user);
}
parent::initialize();

    $this->loadComponent('RequestHandler');
    $this->loadComponent('Flash');
     $this->loadComponent('Auth', [
    'authenticate' => [
        'Form' => [
            'fields' => ['username' => 'username', 'password' => 'password'] // Password and Username fields are pre-define in cakephp.
        ]
    ]
]);
UsersController.php

 parent::initialize();

    $this->loadComponent('RequestHandler');
    $this->loadComponent('Flash');
     $this->loadComponent('Auth', [
    'authenticate' => [
        'Form' => [
            'fields' => ['username' => 'ab_mail', 'password' => 'ab_pass']
        ]
    ]
]);
 public function add()
{
    $user = $this->Users->newEntity();
    if ($this->request->is('post'))
    {
        $user = $this->Users->patchEntity($user, $this->request->data);
        if ($this->Users->save($user)) 
        {
            $this->Flash->success(__('inserted!'));
            return $this->redirect(['action' => 'add']);
        }
        $this->Flash->error(__('Error!'));
    }
    $this->set('user', $user);
}
parent::initialize();

    $this->loadComponent('RequestHandler');
    $this->loadComponent('Flash');
     $this->loadComponent('Auth', [
    'authenticate' => [
        'Form' => [
            'fields' => ['username' => 'username', 'password' => 'password'] // Password and Username fields are pre-define in cakephp.
        ]
    ]
]);

将视图中的表单元素更改为:

<?= $this->Form->input('ab_mail') ?>
<?= $this->Form->input('ab_pass') ?>

将视图中的表单元素更改为:

<?= $this->Form->input('ab_mail') ?>
<?= $this->Form->input('ab_pass') ?>

需要在AppController.php中进行更改

 parent::initialize();

    $this->loadComponent('RequestHandler');
    $this->loadComponent('Flash');
     $this->loadComponent('Auth', [
    'authenticate' => [
        'Form' => [
            'fields' => ['username' => 'ab_mail', 'password' => 'ab_pass']
        ]
    ]
]);
 public function add()
{
    $user = $this->Users->newEntity();
    if ($this->request->is('post'))
    {
        $user = $this->Users->patchEntity($user, $this->request->data);
        if ($this->Users->save($user)) 
        {
            $this->Flash->success(__('inserted!'));
            return $this->redirect(['action' => 'add']);
        }
        $this->Flash->error(__('Error!'));
    }
    $this->set('user', $user);
}
parent::initialize();

    $this->loadComponent('RequestHandler');
    $this->loadComponent('Flash');
     $this->loadComponent('Auth', [
    'authenticate' => [
        'Form' => [
            'fields' => ['username' => 'username', 'password' => 'password'] // Password and Username fields are pre-define in cakephp.
        ]
    ]
]);
这肯定会奏效的


谢谢:)

需要在AppController.php中进行更改

 parent::initialize();

    $this->loadComponent('RequestHandler');
    $this->loadComponent('Flash');
     $this->loadComponent('Auth', [
    'authenticate' => [
        'Form' => [
            'fields' => ['username' => 'ab_mail', 'password' => 'ab_pass']
        ]
    ]
]);
 public function add()
{
    $user = $this->Users->newEntity();
    if ($this->request->is('post'))
    {
        $user = $this->Users->patchEntity($user, $this->request->data);
        if ($this->Users->save($user)) 
        {
            $this->Flash->success(__('inserted!'));
            return $this->redirect(['action' => 'add']);
        }
        $this->Flash->error(__('Error!'));
    }
    $this->set('user', $user);
}
parent::initialize();

    $this->loadComponent('RequestHandler');
    $this->loadComponent('Flash');
     $this->loadComponent('Auth', [
    'authenticate' => [
        'Form' => [
            'fields' => ['username' => 'username', 'password' => 'password'] // Password and Username fields are pre-define in cakephp.
        ]
    ]
]);
这肯定会奏效的


谢谢:)

已修复。如果有人对解决方案感兴趣,只需添加一条注释。已修复。如果有人对解决方案感兴趣,只需添加评论即可。