2013-08-13 6 views
2

CakePhp 1.1을 1.2 이상으로 업그레이드하고 있습니다 ... 마침내.

양식 유효성 검사에 문제가 있습니다. 설명서에서 $ html-> tagErrorMsg가 사용되지 않으며 $ form-> error로 변경해야한다는 것을 알았습니다.

모든 위치에서이 작업을 수행했지만 오류는 표시되지 않습니다. 그들은 내 1.1 버전에서 잘 작동합니다.

<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> 

.ctp 지금 IS : 모델에

<div class="column span-5"> 
<?php echo $form->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 $form->error('Account/firstname', 'Please enter a first name.');?></span></div> 
</div> 

(account.php) : 여기

는 BE하는 데 사용되는 .ctp의 코드

.ctp의 내가 바꿨다 :

var $validate = array(
      'firstname' => VALID_NOT_EMPTY, 
    ); 

:

var $validate = array(
     'firstname' => 'notEmpty', 
); 

내가 뭘 잘못입니까? 1.2 이상에서 올바른 양식 유효성 검증의 예를 포함 시키시겠습니까?

답변

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 파일에서 "계정 /"참조를 제거해야했습니다.

<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> 

그것은 내 컨트롤러는 또한 복수의 규칙을 사용하여 명명되지 않았 음을 밝혀 :

다음은 올바른 CTP입니다. 그래서 나는 $ form-> create()가 올바르게 작동하도록 추가해야만했다.

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

그것은 대신

<form action="<?php echo $html->url('/account/register/'); ?>" method="post"> 
의 CTP에서 양식의 시작 부분에 간다