OK,我解決我的問題,here是,我找到了一個例子。他們已經添加了鏈接下載照片是這樣的:
<ul class='gallery clearfix'>
<li>
<a href='./uploads/1f.jpg' rel='prettyPhoto[gallery1]' title='Nature Photo One' >
<img src='./uploads/1t.jpg' border='0' alt='' link='<a href="download.php?f=1f.jpg" class="url">Download This Photo</a>' />
</a>
</li>
// REST OF THE IMAGES
</ul>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'light_rounded'});
});
</script>
有必要做出一些改變jquery.prettyphoto.js文件。我用v 3.1.2可以下載here
這是我用我提到before
(function($) {
$.prettyPhoto = {version: '3.1.4'};
$.fn.prettyPhoto = function(pp_settings) {
pp_settings = jQuery.extend({
//....
social_tools: '<div class="pp_social"><span class="pp_link"></span></div>'
// I deleted the rest in social_tools since I wasn't going to use them, you can just add this to the begining of it.
}, pp_settings);
//....
/*
* Initialize prettyPhoto.
*/
$.prettyPhoto.initialize = function() {
//...
pp_links=(isSet)?jQuery.map(matchedObjects,function(n,i){if($(n).attr('rel').indexOf(theRel)!=-1)return($(n).find('img').attr('link'))?$(n).find('img').attr('link'):"";}):$.makeArray($(this).find('img').attr('link'));
//...
}
//...
$.prettyPhoto.open = function(event) {
//....
if(pp_links[set_position]!=""){$pp_pic_holder.find('.pp_link').show().html(unescape(pp_links[set_position]));}else{$pp_pic_holder.find('.pp_link').hide();}
//....
}
的例子中所做的更改,如果你想在警予的prettyphoto extention使用它。您可以用您修改的文件替換javaScript文件。然後:
<?php
$this->beginWidget('ext.prettyPhoto.PrettyPhoto', array(
'id'=>'pretty_photo',
// prettyPhoto options
'options'=>array(
'opacity'=>0.60,
'modal'=>true,
'theme'=> 'light_rounded'
),
));
?>
<div class="column4-front image-gallery">
<a href="/files/immagini/<?php echo $data->image; ?>" rel="prettyPhoto[pp_gal]" title="<?php echo $data->caption; ?>">
<img src="/files/immagini/thumb/<?php echo $data->image; ?>" link='<a href="<?php echo $this->createUrl('compania/downloadimage',array('f'=>$data->image)); ?>" class="url">Scarica questo foto</a>'/>
</a>
</div>
<?php $this->endWidget('widgets.prettyPhoto');?>
這添加到相關的控制器,對我來說CompaniaController:
public function actionDownloadImage()
{
$filename = $_GET['f'];
$fileDir='path to image';
Yii::app()->request->sendFile(
$filename,
file_get_contents($fileDir.$filename)
);
}
沒有PrettyPhoto JS變化是必要的。看我的解決方案。謝謝。 –