doudong0425 2014-04-01 09:51
浏览 34
已采纳

CakePHP Auth不允许显示图像

I have a gallery that was being displayed correctly but after I made the permissions using Auth the thumbnails no long display an image, but when i delete the function beforFIlter(), public function isAuthorized($user) and Auth component from AppController,it works somehow, how can this be fixed? I am using CakePHP 2.4.4 and timthumb 2 and fancybox.

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

View

<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

  • 写回答

1条回答 默认 最新

  • duanmu2941 2014-04-01 16:04
    关注

    I think found the solution. Try doing this.

    put debug mode to 0; empty the timthumb folder. refresh your page.

    EDIT (moved from comments)

    don't use px, this :

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

    should be :

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

    UPDATE Use the following lines on TimthumbController class. It will work like a charm.

    public function beforeFilter(){
        $this->Auth->allow('image');
    }//end of beforeFilter
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值