gpt4 book ai didi

php - 使用博客教程创建自定义条目 'clients' ,我无法追踪问题

转载 作者:行者123 更新时间:2023-11-29 23:44:42 25 4
gpt4 key购买 nike

我最初有一些基本的身份验证和表单验证,但为了排除故障而将这两者都删除了。当在/clients/add 填写并提交后没有任何反应。当对/posts/add 执行此操作时,它可以正常工作。

Controller /ClientsController.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'));
}
}
}

模型/Client.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');
?>

Here是数据库结构的屏幕截图,以防是数据库相关问题。

最佳答案

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

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

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

关于php - 使用博客教程创建自定义条目 'clients' ,我无法追踪问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26004827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com