2014-04-01 55 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