我有从 youtube 视频复制的表单验证,但它是使用 cakephp 1.3 编码的。所以我很难将它迁移到 2.1
CommentsController.php - 函数 validate_form()
function validate_form()
{
if($this->RequestHandler->isAjax())
{
$this->request->data['Comment'][$this->request['form']['field']] = $this->request['form']['value'];
$this->Comment->set($this->request->data);
if($this->Comment->validates())
{
$this->autorender = FALSE;
}
else
{
$error = $this->validateErrors($this->Comment);
$this->set('error', $error[$this->request->params['data']['field']]);
}
}
}
validate_form.ctp
<?php echo $error; ?>
错误:
Undefined variable: error [APP\View\Comments\validate_form.ctp, line 1]
为什么它是未定义的?请帮助我,如果我不这样做,我的老板会解雇我。我只是一个试用期的员工,一个 5 天大的初级网络开发人员