Forms 更新$html->;tagErrorMsg从CakePhp 1.1到1.2

Forms 更新$html->;tagErrorMsg从CakePhp 1.1到1.2,forms,validation,cakephp,cakephp-1.2,Forms,Validation,Cakephp,Cakephp 1.2,我正在将CakePhp 1.1升级到1.2(及更高版本)。。。最后 我在表单验证方面遇到问题。 我从文档中了解到,$html->tagErrorMsg已被弃用,需要更改为$form->error 我在所有位置都执行了此操作,但不会显示错误。它们在我的1.1版本中运行良好 这是来自.ctp的代码 .ctp过去是: <div class="column span-5"> <?php echo $html->input('Account/firstname', array('s

我正在将CakePhp 1.1升级到1.2(及更高版本)。。。最后

我在表单验证方面遇到问题。 我从文档中了解到,$html->tagErrorMsg已被弃用,需要更改为$form->error

我在所有位置都执行了此操作,但不会显示错误。它们在我的1.1版本中运行良好

这是来自.ctp的代码

.ctp过去是:

<div class="column span-5">
<?php echo $html->input('Account/firstname', array('size' => 20, 'class'=>'span-4 first last txt')); ?>
</div>
<div class="column span-3 last"><span class="my_error"><?php echo $html->tagErrorMsg('Account/firstname', 'Please enter a first name.');?></span></div>
</div>
致:

我做错了什么? 请您在1.2及更高版本中提供一个正确表单验证的示例,好吗?

我想出来了。 在1.1和1.2之间还有一些约定更改

在控制器中,我必须添加:

                $this->Account->set($this->data);
            if ($this->Account->validates()) {
                // validated logic
            } else {
                // didn't validate logic
                $errors = $this->Account->validationErrors;
            }
然而,这也不太管用。 我还必须删除ctp文件中的“Account/”引用

以下是正确的ctp:

    <div class="column span-5">
<?php echo $form->input('firstname', array('size' => 20, 'class'=>'span-4 first last txt')); ?>
</div>
<div class="column span-3 last"><span class="my_error"><?php echo $form->error('firstname', 'Please enter a first name.');?></span></div>
</div>

事实证明,我的控制器也没有使用复数约定命名。因此,为了让$form->create()正常工作,我还必须添加它

 <?php echo $form->create('Account', array('action' => 'register')); ?>

它位于ctp中表格的开头,而不是

<form action="<?php echo $html->url('/account/register/'); ?>" method="post">

    <div class="column span-5">
<?php echo $form->input('firstname', array('size' => 20, 'class'=>'span-4 first last txt')); ?>
</div>
<div class="column span-3 last"><span class="my_error"><?php echo $form->error('firstname', 'Please enter a first name.');?></span></div>
</div>
 <?php echo $form->create('Account', array('action' => 'register')); ?>
<form action="<?php echo $html->url('/account/register/'); ?>" method="post">