采纳答案成功!
向帮助你的同学说点啥吧!感谢那些助人为乐的人
环境windows,其余都一样,数据库中pic_url地址类似/img/lovelife/smimg/loveshopping/img1.jpg,我插入channel.html中的网址也是上面那个,但是正确路径应该是/static/img/lovelife/smimg/loveshopping/img1.jpg,为什么老师的就能正确生成,我的就不行?
public function GetChannelPart($data, $i = 1) { $html = file_get_contents(SITE_PATH . '/public/template/channel_part.html'); $res_html = ''; foreach ($data as $channel_data) { $part_html = $html; $part_sub_channel = $part_goods = $part_goods_foot = $part_brand = ''; $part_html = str_replace('<{i}>', $i, $part_html); $part_html = str_replace('<{channel_title}>', $channel_data['Info']['title'], $part_html); //子栏目部分, foreach ($channel_data['SubChannel'] as $sub_channel) { $part_sub_channel .= "<li><a href=\"" . $sub_channel['url'] . "\">" . $sub_channel['title'] . "</a></li>"; } $part_html = str_replace('<{channel_link}>', $part_sub_channel, $part_html); //商品部分, $part_html = str_replace('<{main_goods}>', '<a href="' . $channel_data['Goods'][1][0]['url'] . '"><img src="' . '/static' . $channel_data['Goods'][1][0]['pic_url'] . '"></a>', $part_html); //小商品部分, foreach ($channel_data['Goods'][2] as $good) { $part_goods .= '<li><a href="' . $good['url'] . '"><p>' . $good['title'] . '</p><p>' . $good['subtitle'] . '</p><img src="' . '/static' . $good['pic_url'] . '"></a></li>'; } $part_html = str_replace('<{four_goods}>', $part_goods, $part_html); //小商品部分, foreach ($channel_data['Goods'][3] as $good) { $part_goods_foot .= '<li><a href="' . $good['url'] . '"><p>' . $good['title'] . '</p><p>' . $good['subtitle'] . '</p><img src="' . '/static' . $good['pic_url'] . '"></a></li>'; } $part_html = str_replace('<{foot_goods}>', $part_goods_foot, $part_html); //品牌,, foreach ($channel_data['Brand'] as $good) { $part_brand .= '<li><a href="' . $good['url'] . '"><img src="' . '/static' . $good['pic_url'] . '"></a></li>'; } $part_html = str_replace('<{brands}>', $part_brand, $part_html); $res_html .= $part_html; $i++; } return $res_html; }
这样就好了
在给一个小提示,页面静态后,手机哪里,中兴新品下面会缺一张图片,原因是那一张三星手机的图片格式是png,而数据库里的是 jpg
这个方法好,还简单,我都没想到,厉害
我自问自答,老师的数据库pic_url少了/static/,我看了两遍才看出来。
登录后可查看更多问答,登录/注册
全面涵盖PHP缓存核心知识 建立完整知识体系 解决各类缓存相关问题
645 5
885 4
557 3
787 2
930 2