CakePHP Auth不允许显示图像

时间:2014-04-01 09:51:00

标签: php jquery cakephp authorization fancybox-2

我有一个正确显示的图库但在使用Auth创建权限后,缩略图不再显示图像,但是当我删除function beforFIlter()public function isAuthorized($user)和{来自Auth的{​​1}}组件,它以某种方式工作,如何解决? 我正在使用CakePHP 2.4.4和timthumb 2以及fancybox。

** AppController **

AppController

GalleriesController

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');   


}

查看

    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']
    }

Error image1

Error image2

1 个答案:

答案 0 :(得分: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)));

<强>更新TimthumbController class上使用以下行。它会像魅力一样发挥作用。

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