我最近才开始使用 CakePHP,并且无法在我为测试表单而创建的联系人应用程序中工作。一旦我$validate
在模式中设置了数组,星号就会出现在表单上,但是,当我提交表单时,我仍然没有收到验证消息。这是我的代码:
/app/View/Contacts/index.ctp
<h1>Contact Form</h1>
<?php
echo $this->Form->create('Contact');
echo $this->Form->input('name');
echo $this->Form->input('age');
echo $this->Form->end('Submit This Form!!!');
?>
/app/Controller/ContactsController.php
<?php
class ContactsController extends AppController {
public $helpers = array('Html', 'Form');
public function index() {
}
}
?>
/app/Model/Contact.php
<?php
class Contact extends AppModel {
var $useTable = false;
public $validate = array(
'name' => array(
'rule' => 'notEmpty',
'message' => 'Cannot leave this field blank.'
),
'age' => array(
'rule' => 'notEmpty',
'message' => 'Cannot leave this field blank.'
)
);
}
?>