簡體   English   中英

cakephp控制器的add函數問題

[英]cakephp controller problems with the add function

在將用戶輸入用戶表時遇到問題。 我去..users / add,我的表單按預期顯示。 我填寫表格並按下提交按鈕但沒有任何反應。 屏幕閃爍,顯然什么也沒做。 沒有新記錄出現在名為users的數據庫表中。

我可以在..users / index中查看所有現有的用戶記錄,這樣就可以了。 有人想過嗎?

控制器

<?php 

 class UsersController extends AppController {

public $helpers = array('Html', 'Form', 'Session');
public $components = array('Session');

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

public function add() {
    if ($this->request->is('user')) {
        $this->User->create();
        if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('User has been created.'));
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('Unable to create the user.'));
        }
    }
}
 }

?>

提前致謝。 DS

我不知道你使用的是哪個版本的CakePHP,但根據CakePHP 2.0文檔,沒有這樣的內置探測器叫做user 嘗試改變

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

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

參考: http//book.cakephp.org/2.0/en/controllers/request-response.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM