doushi6932 2015-08-30 17:30
浏览 78

聪明的功能分配PHP

i have a function in smarty that checks if the row called "mikaphotos" is empty. If the row is empty, it's ok and doesnt happen anything, and if it's not empty..it takes the value in $path variable. Now my assin is:

$smarty->assign("mikaPhotos", getTheImages("SOMEPATH",400), true);

and my getTheImages function is:

getTheImages($path,$width){
 $dirname = $path; //the path
 $images = glob($dirname."*.png");//get the png images from directory
 foreach($images as $image) {
 echo '<img src="'.$dirname.'/'.$image.'" width="'.$width.'" /><br />';//echo all the images in SOMEPATH
 }
}

now in my file.tpl .. i put:{$mikaPhotos} and it's not working. I think there is some problem in my code, but i do not know how to do that. any help please?

  • 写回答

2条回答 默认 最新

  • dtmjl4427 2015-08-30 17:36
    关注

    Function assign in smarty assigns(!) value returned by getTheImages function to mikaPhotos variable. So, your getTheImages function should return a string instead of echoing. For example, something like:

    getTheImages($path,$width){
        $result = '';
        $dirname = $path; //the path
        $images = glob($dirname."*.png");//get the png images from directory
        foreach($images as $image) {
            $result .= '<img src="'.$dirname.'/'.$image.'" width="'.$width.'" /><br />';
        }
    
        return $result;    // return html for all your images as a string
    }    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行