Validation Can´;不显示验证消息

Validation Can´;不显示验证消息,validation,cakephp,file-upload,Validation,Cakephp,File Upload,我是个新手。我在其他帖子上尝试过很多解决方案,但我就是做不好。我的验证中的mesages没有显示,但是如果大小验证没有通过,文件输入字段的值将变为null,但是扩展名valdiation似乎也不起作用。为什么没有显示消息,扩展验证也不起作用? 我使用的是CakePHP2.4.4 控制器 public function admin_upload_image(){ $this->set('title_for_layout', 'Inserir Fotografias')

我是个新手。我在其他帖子上尝试过很多解决方案,但我就是做不好。我的验证中的mesages没有显示,但是如果大小验证没有通过,文件输入字段的值将变为null,但是扩展名valdiation似乎也不起作用。为什么没有显示消息,扩展验证也不起作用? 我使用的是CakePHP2.4.4

控制器

    public function admin_upload_image(){
        $this->set('title_for_layout', 'Inserir Fotografias');
        if(!$this->Session->check('User')) {
            $this->Session->setFlash('Está a aceder a uma zona restrita. Por favor faça Login.');
            $this->redirect(array(
                            'controller' => 'users',
                            'action' => 'login'));
        }

        $this->layout = 'admin_index';
        if($this->request->is('post') || $this->request->is('put')) {
          /*  $file = $this->request->data['gallery_images']['path']['name'];*/
        $file = array(
                'GalleryImage' => array(
                'path' => $this->request->data['gallery_images']['path']['name']
                                        )
                );
            move_uploaded_file($this->data['gallery_images']['path']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/html/PushUp/app/webroot/img/gallery/' . $this->data['gallery_images']['path']['name']);

            $this->loadModel('GalleryImage');

            $this->GalleryImage->create();
           //debug($file);
           //die;
            if($this->GalleryImage->save($file)){
                $validationErrors = $this->GalleryImage->invalidFields();
                $this->Session->setFlash($validationErrors['path']); // named key of the rule
                $this->Session->setFlash(__('Evento guardado com sucesso.'));
            }
            //else{

                //$error = $this->Notification->validationErrors;
                //$this->set('error', $error);

                //$this->Session->setFlash(__($error), 'Flash/warning');
            //}
        }
    }
查看

<h2>Adicionar Fotografia</h2>
<?php
echo "<br>";
echo $this->Form->create('GalleryImage',array('type'=>'file'));
echo $this->Form->file('gallery_images.path');
echo "<br>";
echo $this->Form->submit(__('Guardar'), array('class' => 'btn btn-success','formnovalidate' => false)) ;
echo $this->Form->end();
/*if ($this->Form->isFieldError('path')) {
    echo $this->Form->error('path');
}*/
?>
pr($this->GalleryImage->invalidFields())

Notice (8): Undefined index: gallery_images [APP\Controller\GalleriesController.php, line 50]
Notice (8): Undefined index: gallery_images [APP\Controller\GalleriesController.php, line 53]
Notice (8): Undefined index: gallery_images [APP\Controller\GalleriesController.php, line 53]
Array
(
[path] => Array
    (
        [0] => Seleccione uma fotografia por favor.
        [1] => Seleccione uma fotografia por favor.
    )

)
使用表单->输入 “构建块”功能,如和,只是输入。生成表单的常规方法是使用(或)方法:

或者显式地呈现错误 或者,可以显式呈现验证错误:

echo $this->Form->file('path');
echo $this->Form->error('path');

你能在控制器中使用
if($this->GalleryImage->save($file))/*你的代码*/else{pr($this->ModelName->invalidFields());}
进行调试吗?检查是否未从模型中获取错误,或者控制器是否正确接收错误,但视图未显示错误。用
pr()
的结果更新你的问题(如果你没有得到一个错误数组,则不需要它)。@Nunser我更新了我的问题。我使用
echo$this->Form->error('path')显示了一个错误,但这是错误的。我得到了
is_valid
规则消息,而不是
size
消息,因为我试图上传的文件超过了用于测试12MB图像的1.5MBI,我的php上传限制设置为20MB。我需要知道的是,为什么没有显示消息,以及为什么我使用您发布的代码出现错误。因此,您是说这是由于上载的文件大小限制造成的?好的,我将标记您的问题作为解决方案。谢谢
Notice (8): Undefined index: gallery_images [APP\Controller\GalleriesController.php, line 50]
Notice (8): Undefined index: gallery_images [APP\Controller\GalleriesController.php, line 53]
Notice (8): Undefined index: gallery_images [APP\Controller\GalleriesController.php, line 53]
Array
(
[path] => Array
    (
        [0] => Seleccione uma fotografia por favor.
        [1] => Seleccione uma fotografia por favor.
    )

)
echo $this->Form->input('path', array('type' => 'file'));
echo $this->Form->file('path');
echo $this->Form->error('path');