我正在CakePHP項目上工作並遇到問題。 我們編寫了一個Ajax函數,它將數據發送到php函數,該函數將一個文件夾(德語:ordner)添加到相應的數據庫。它工作得很好,但我們希望將「Ordners」的index.ctp移動到「Pages」目錄,以便它成爲我們的主頁面。現在這個函數仍然可以工作,但是當點擊按鈕時它會從Ajax函數中拋出錯誤消息。我們寫了不同的功能,同樣的事情也發生在那裏。更改索引路徑後CakePHP出錯
代碼從JavaScript:從OrdnersController
$.ajax({
type: 'POST',
url: '/cake1/ordners/add',
data: sendData,
success: function (data, textStatus, xhr) {
//alert(sendData);
},
error: function (xhr, textStatus, error) {
alert(textStatus);
}
});
附加功能:
public function add() {
$ordner = $this->Ordners->newEntity();
if ($this->request->is('post')) {
$ordner = $this->Ordners->patchEntity($ordner, $this->request->data);
if ($this->Ordners->save($ordner)) {
//$this->Flash->success(__('Your folder has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('Unable to add your folder.'));
}
$this->set('post', $ordner);
}
routes.php文件
$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'index']);