提交数据只重新加载页面,没有错误或消息由CakePHP给出。 代码遵循与博客教程相同/相似的结构。CakePHP数据不保存/添加到数据库
视图代码
<?php
echo $this->Form->create('Sm');
echo $this->Form->input('recievers', array('rows' => '1'));
echo $this->Form->input('subject');
echo $this->Form->input('message');
echo $this->Form->end('SEND');
?>
控制器代码
public function send() {
if ($this->request->is('sm')) {
$this->Sm->create();
if ($this->Sm->save($this->request->data)) {
$this->Session->setFlash('Sms has been added to the database');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to send sms.');
}
}
}
型号代码
class Sm extends AppModel {
public $validate = array(
'subject' => array(
'rule' => 'notEmpty'
),
'message' => array(
'rule' => 'notEmpty'
),
'recievers' => array(
'rule' => 'notEmpty'
)
); }
导出SQL
CREATE TABLE IF NOT EXISTS `sms` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`subject` varchar(150) DEFAULT NULL,
`message` text,
`sender` varchar(50) DEFAULT NULL,
`recievers` text,
`sent` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
向上投票的问题,因为我看到没有直接的理由,这个问题获得了负分。所有必需的代码都包含在内,整齐地格式化,OP正在尝试根据手册中的示例启动CakePHP。 – thaJeztah 2013-03-04 14:18:53
谢谢你,先生:)至于这个问题,我最后的答案是使用烘焙工具来生成代码。下面的建议答案都没有做到这一点。可能会花一些时间比较我的原始代码和生成的代码以找到正确的答案。 – ChrisRSA 2013-03-05 16:15:07