2014-04-01 54 views
0

图像I具有正被正确显示图库但之后,我提出使用Auth缩略图的权限没有长显示图像,但是当我删除从function beforFIlter()public function isAuthorized($user)Auth部件AppController,它以某种方式工作,这怎么解决? 我正在使用CakePHP 2.4.4和timthumb 2和fancybox。CakePHP的验证doesn't允许显示

** **的AppController

class AppController extends Controller { 
public $components = array('DebugKit.Toolbar', 
          'Session','Auth' => array(
               'loginRedirect' => array('controller' => 'admins', 'action' => 'admin_index'), 
               'logoutRedirect' => array('controller' => 'home', 'action' => 'index'), 
               'authorize' => array('Controller') 
               ) 
         ); 

public function isAuthorized($user){ 
    if(isset($user['role']) && $user['role']==='admin'){ 
     return true; //admin pode acedeer a todas as actions 
    } 
    return false; // os outros utilizadores não podem 
} 
function beforeFilter(){ 
    $this->Auth->allow('index','ShowImages','ShowShowbill','ShowVideos','login'); 

} 
public $helpers = array('Html' , 
         'Form' , 
         'Timthumb.Timthumb', 
         'Paginator', 
         'Session', 
         'Js', 
         'Fancybox.Fancybox'); 


} 

GalleriesController

public function ShowImages(){ 
     $this->layout = 'default'; 
     $this->loadModel('GalleryImage'); 
     $gallery_images = $this->GalleryImage->find('all'); 
     $this->set('gallery_images', $gallery_images); 
    //$image_display = $gallery_image['path'] 
    } 

查看

<h2>Galeria</h2> 
<br> 
<table width="100%"> 
<tr> 
    <?php 
     $i=0; 
     foreach($gallery_images as $gallery_image):?> 
    <td align="center" class="thumbnail" style="display:inline-block;"> 
    <?php 
     $src3 =$this->webroot. 'img/gallery/' .$gallery_image['GalleryImage']['path']; 
     //$src3 = 'img/gallery/' .$gallery_image['GalleryImage']['path']; 
     $this->Fancybox->setProperties(array( 
      'class' => 'fancybox3', 
      'className' => 'fancybox.image', 
      'title'=>'Single Image', 
      'rel' => 'gallery1' 
      ) 
     ); 
     $this->Fancybox->setPreviewContent($this->Timthumb->image('/img/gallery/' . $gallery_image['GalleryImage']['path'] , array('width' => 267, 'height' => 189))); 

     $this->Fancybox->setMainContent($src3); 
     echo $this->Fancybox->output(); 
    ?> 
    </td> 
    <?php $i++; 
     if($i==4){ 
      echo "</tr><tr>"; 
      $i=0; 
     } 
    ?> 
<?php endforeach ?> 
</tr> 

Error image1

Error image2

+0

您的'GalleriesController'是否也定义了'beforeFilter()'回调函数?如果是这样,确保它正确地调用'parent :: beforeFilter()'! – ndm

+0

否控制器中没有'beforeFilter()',只有上传和删除图像的操作。 – SunT

+0

任何调试消息?像Auth消息一样? –

回答

1

我觉得找到了解决办法。 尝试这样做。

将调试模式设置为0; 清空timthumb文件夹。 刷新你的页面。

编辑(从评论移动)

不使用px,这样的:

$this->Fancybox->setPreviewContent($this->Timthumb->image('/img/gallery/' . $gallery_image['GalleryImage']['path'] , rray('width' => '267px', 'height' => '189px'))); 

应该是:

$this->Fancybox->setPreviewContent($this->Timthumb->image('/img/gallery/' . gallery_image['GalleryImage']['path'] , array('width' => 267, 'height' => 189))); 

UPDATE 使用下列上线TimthumbController class。它会像魅力一样工作。

public function beforeFilter(){ 
    $this->Auth->allow('image'); 
}//end of beforeFilter 
+0

我得到:_Error:发生内部错误_。 – SunT

+0

我在这里试过。在调试模式2中,如果加载了认证组件,则timthumb不起作用。但是,如果调试模式设置为0,它可以与Auth一起使用。它可能是timthumb上的一个错误。 现在你需要设置调试模式为2,并让我们显示错误.. –

+0

设置调试为2和加载调试不显示任何错误消息,我也尝试使用Auth加载和调试模式设置为0,它没有工作。 – SunT