Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cakephp应用程序中缺少验证消息_Php_Cakephp - Fatal编程技术网

cakephp应用程序中缺少验证消息

cakephp应用程序中缺少验证消息,php,cakephp,Php,Cakephp,我正在尝试为cakephp应用程序添加布局,但现在不再显示我的验证消息。验证博客条目上的评论时,不会显示假定位于顶部的验证消息 如果更改布局意味着您错过了添加 <?php if ($this->Session->check('Message.flash')){ echo $this->Session->flash(); } ?> 第一个代码负责显示消息,而第二个代码负责设置消息 但是代码肯定会有更多帮助:)这是我在comments\u controlle

我正在尝试为cakephp应用程序添加布局,但现在不再显示我的验证消息。验证博客条目上的评论时,不会显示假定位于顶部的验证消息

如果更改布局意味着您错过了添加

<?php
if ($this->Session->check('Message.flash')){
  echo $this->Session->flash();
}
?>
第一个代码负责显示消息,而第二个代码负责设置消息


但是代码肯定会有更多帮助:)

这是我在comments\u controller.php中的add函数

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,我的帖子和评论就在这里:

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

我知道这很旧,但必须确保在应用程序/views/layouts/default.ctp(或此应用程序的任何布局)中的某个地方可以看到以下代码



如果没有要显示的消息,它将不回显任何内容,但如果有消息,它将相应地输出。

请编码?这样我们就可以知道什么是错的正如jun所说,你应该发布相关的代码。特别是验证数组(或设置错误消息的任何位置)和模板(ctp)中应该为初学者显示消息的部分。
<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>
function index($entry_id = null) {

    if (isset($entry_id)){
        $entry = $this->Post->findAllById($entry_id);

        $comments = $this->Post->Comment->getCommentsFromPostID($entry_id);

        $this->set('entry' , $entry);
        $this->set('mathCaptcha', $this->MathCaptcha->generateEquation());
        $this->render('entry');

    }
    else{

        $posts = $this->Post->find('all');  

        $this->set(compact('posts'));
    }
}
<?php echo $this->Session->flash(); ?>