0

I'm trying to implement the phpFlickr-wrapper (https://github.com/dan-coulter/phpflickr) in my MODX-project.

I tried a simple code i found here on stackoverflow and put it in a snippet called "Flickr":

//include the core file
if(!class_exists("phpFlickr")) require_once './assets/phpflickr-master/phpFlickr.php';

// include the config file
require_once('./assets/phpflickr-master/config.php');

$f = new phpFlickr($key, $api_secret);

$mySetID = $album; 

$mySet = $f->photosets_getPhotos($mySetID, NULL, NULL);
foreach ($mySet['photoset']['photo'] as $photo) {
    echo '<div><img src="'. $f->buildPhotoURL($photo, 'medium') .'" alt="" /></div>';
}

The snippet call:

[[!Flickr? &setname=`[[+tv.FickrID]]`]]

The TV "FlickrID" holds the ID of the wanted album.

This is working fine for one album. But when I try to output a second gallery the output gets stopped after the first snippet-call. The second time the snippet-call is made it stops with this entry in the MODX error-log:

 ...75.include.cache.php : 18) PHP warning: Invalid argument supplied for foreach()

How can I display more than one album on the same page, any idea?

4

1 回答 1

0

问题解决了...

我只需要将“config.php”文件中的内容包含在片段中,而不是通过“require_once”代码行来引用它。

<?php
$album = $modx->getOption('setname',$scriptProperties,'');

//include the core file
if(!class_exists("phpFlickr")) require_once './assets/phpflickr-master/phpFlickr.php';
if(!class_exists("PEAR")) require_once './assets/phpflickr/PEAR/PEAR.php'; 

$key = "<flickr-api-key>";
$api_secret = "<flickr-api-secret>";
$username="<flickr-username>";

$f = new phpFlickr($key, $api_secret);

$f->enableCache("fs", "./assets/phpflickr-master/cache");

$mySetID = $album; 
$mySet = $f->photosets_getPhotos($mySetID, NULL, NULL);
foreach ($mySet['photoset']['photo'] as $photo) {
    $output .= '<div><a rel="lightbox[]" href="'. $f->buildPhotoURL($photo, 'large') .'"><img src="'. $f->buildPhotoURL($photo, 'medium') .'" alt="" /></a></div>';
}

return $output;
于 2019-12-14T19:11:15.053 回答