使用博客教程创建自定义条目';客户端';,我可以';Don’我没有追查到这个问题


Used the Blog tutorial to create custom entry 'clients', I can't track down the issue

我最初有一些基本的身份验证和表单验证,但为了排除故障,我去掉了这两个。当在/clients/add填写并提交后,没有发生任何事情。当对/posts/add执行此操作时,它可以正常工作。

控制器/客户端控制器.php

<?php
class ClientsController extends AppController {
    public $helpers = array('Html', 'Form');

    public function index() {
        $this->set('clients', $this->Client->find('all'));
    }

    public function view($id = null) {
        if (!$id) {
            throw new NotFoundException(__('Invalid client'));
        }
        $client = $this->Client->findById($id);
        if (!$client) {
            throw new NotFoundException(__('Invalid client'));
        }
        $this->set('client', $client);
    }

    public function add() {
        if ($this->request->is('client')) {
            $this->Client->create();
            if ($this->Client->save($this->request->data)) {
                $this->Session->setFlash(__('Your client has been saved.'));
                return $this->redirect(array('action' => 'index'));
            }
            $this->Session->setFlash(__('Unable to add your client.'));
        }
    }

    public function edit($id = null) {
        if (!$id) {
            throw new NotFoundException(__('Invalid client'));
        }
        $client = $this->Client->findById($id);
        if (!$client) {
            throw new NotFoundException(__('Invalid client'));
        }
        if ($this->request->is(array('post', 'put'))) {
            $this->Client->id = $id;
            if ($this->Client->save($this->request->data)) {
                $this->Session->setFlash(__('Your client has been updated.'));
                return $this->redirect(array('action' => 'index'));
            }
            $this->Session->setFlash(__('Unable to update your client.'));
        }
        if (!$this->request->data) {
            $this->request->data = $client;
        }
    }
    public function delete($id) {
        if ($this->request->is('get')) {
            throw new MethodNotAllowedException();
        }
        if ($this->Client->delete($id)) {
            $this->Session->setFlash(
                __('The client with id: %s has been deleted.', h($id))
            );
            return $this->redirect(array('action' => 'index'));
        }
    }
}

型号/客户端.php

<?php
class Client extends AppModel {
}

查看/Clients/add.ctp

<h1>Add Client</h1>
<?php
echo $this->Form->create('Client');
echo $this->Form->input('contact');
echo $this->Form->input('customer');
echo $this->Form->input('state');
echo $this->Form->input('district');
echo $this->Form->end('Save Client');
?>

以下是数据库结构的屏幕截图,以防出现与数据库相关的问题。

  what is $this->request->is('client') ?

请不要只是复制和替换,它应该是

  $this->request->is('post')