2010-07-22 6 views
0

cakephp 응용 프로그램에 대한 레이아웃을 추가하려고하지만 이제 유효성 검사 메시지가 더 이상 표시되지 않습니다. 블로그 항목에 대한 댓글의 유효성을 검사 할 때 상단에있는 것으로 보이는 인증 메시지가 표시되지 않습니다.cakephp 응용 프로그램에 누락 된 유효성 검사 메시지

+3

코드 pls? 그런 식으로 우리는 무엇이 잘못되었는지 알게 될 것입니다. –

+0

준이 말했듯이, 관련 코드를 게시해야합니다. 특히 유효성 검사 배열 (또는 오류 메시지를 설정하는 곳)과 템플릿의 시작 부분에 메시지를 표시해야하는 부분 (ctp). – webbiedave

답변

0

당신이 레이아웃을 변경하면 현재 컨트롤러에 당신이

다른 가능한 장소 전에

<?php 
if ($this->Session->check('Message.flash')){ 
    echo $this->Session->flash(); 
} 
?> 

을 추가 놓친 것을 의미한다. 두 번째는 메시지를 설정하기위한 책임있는 동안,

$this->Session->setFlash('...'); 

첫 번째 코드는 메시지를 표시 할 책임이있다 : 당신은 같은 코드가있는 경우

검색합니다.

하지만 코드가 도움이 될 것입니다 더 여기

0

: 내 게시물과 댓글이있는 경우 여기에

function add(){ 
    debug($this->data); 
    //if the user submitted a comment post 
    if (!empty($this->data)){ 

     //display the 'add view'  
     $this->Comment->create(); 

     if ($this->MathCaptcha->validates($this->data['Comment']['security_code'])) { 

       if ($this->Comment->save($this->data)){ 
        $this->Session->setFlash(__('The Comment has been added.', true)); 
        $this->redirect('/posts/index/'.$this->data['Comment']['post_id']); 
       } 
       //failed validation 
       else{ 
        debug($this->data); 
        $this->Session->setFlash(__('Comment could not be saved. Please try again.', true)); 

       } 

     } 
     else { 
      $this->Session->setFlash(__('Please enter the correct answer to the math question.', true)); 
      $this->redirect('/posts/index/'.$this->data['Comment']['post_id']); 

     } 

내 entry.ctp입니다 comments_controller.php 내 추가 기능입니다 :

<div id="article"> 


<h2><?php echo $entry[0]['Post']['title']; ?></h2> 
<p class="date"><em>Modified:</em> <?php $date = new DateTime($entry[0]['Post']['modified']); 
    echo $date->format('Y-m-d');?></p> 
<p class="date"><em>Author:</em> <?php echo $entry[0]['User']['username']; ?></p> 


<p class="intro"><?php echo $entry[0]['Post']['content']; ?></p> 

<h2>Comments:</h2> 
<div id="comments_success"></div> 

<!-- show the comment --> 


<?php 

     echo $form->create('Comment', array('action' => 'add')); 

     echo $form->input('name', array('class' => 'validate[required] text-input')); 
     echo $form->input('email', array('class' => 'validate[required,custom[email]] text-input')); 

     echo $form->input('text', array('id' => 'commenttext', 'type' => 'textarea', 'label' => 'Comment:', 'rows' => '10', 'class' => 'validate[required] text-input')); 

     //captcha 
     echo $form->input('security_code', array('label' => 'Please Enter the Sum of ' . $mathCaptcha)); 
     echo $form->input('Comment.post_id', array('value' => $entry[0]['Post']['id'] , 'type' => 'hidden')); 

     echo $form->end('Submit'); 

    ?> 

<!-- comments --> 

<ol> 

<?php 
    foreach ($entry[0]['Comment'] as $comment) :     
?> 
    <li> 
     <h3><?php echo $comment['name']; ?></h3>  
     <p class="date"><em>Date:</em> <?php echo $comment['created']; ?></p> 
     <p class="text"> <?php echo $comment['text']; ?></p>  
    </li>  
<?php 
    endforeach; 
?>    
</ol> 
</div> 

내 posts_controller의 색인 기능입니다.

0

0 나는이 오래 알고 있지만, UST 앱/뷰/레이아웃/default.ctp 어딘가에 볼 다음 코드를 가지고 있는지 확인 (또는이 응용 프로그램의 레이아웃 뭐든)

<?php echo $this->Session->flash(); ?> 

이 표시 할 메시지가 없으면 아무것도 표시하지 않지만 메시지가 있으면 그에 따라 출력됩니다.

관련 문제