ecshop二次开发:商品分类添加图片显示功能
ecshop的分类添加分类图片的功能,下面归类一下:
1、最关键的就是在数据的category表里面加入cat_img字段,用来保存咱们的图片地址,类型就是varchar就可以了。
2、在admin目录下面的templates的category_info.html文件,这个是后天的模板文件,在里面加入
<tr>
<td class="label">{$lang.cat_img}:</td>
<td><input name="cat_img" size="35" type="file" value='' />
{if $cat_info.cat_img}
<img src="images/yes.gif" border="0" alt="" />
{else}
<img src="images/no.gif" alt="" />
{/if}
</td>
</tr>
3、然后修改category.php文件,
在require(dirname(__FILE__) . '/includes/init.php');下增加
/***新增加的开始***/
include_once(ROOT_PATH . 'includes/cls_image.php');
$image = new cls_image($_CFG['bgcolor']);
/***新增加的结束***/4、然后修改category.php文件,if ($_REQUEST['act'] == ‘insert’) 下面加入
$cat['cat_img'] = $image->upload_image($_FILES['cat_img']);
在if ($_REQUEST['act'] == ‘update’) 下面加入
$image = $image->upload_image($_FILES['cat_img']);
if(!empty($image))
{
$cat['cat_img'] = $image;
}5、修改category_tree.lbi文件,内容修改主要集中在以前直接显示category名字的地方加上判断,如果category有图片就是用图片,没有使用文字,我的修改玩如下:
<dl><a href="{$cat.url}"><!--{if $cat.cat_img }-->
<img src="{$cat.cat_img}" alt="" />
<!-- {else } -->{$cat.name|escape:html}<!-- {/if} --></a></dl>
<dd><a href="{$child.url}">
<!--{if $child.cat_img }-->
<img src="{$child.category_img}" alt="" />
<!-- {else } -->
{$child.name|escape:html}
<!-- {/if} -->
</a></dd>6、大家会发现修改了模板,然后自己在后台上传完了图片前台还是不能显示,这事因为系统在读取category数据库的时候没有读取这个字段,所以我们要修改一下读取的地方了,修改文件lib_goods.php,找到函数 get_categories_tree 和 get_child_tree,把里面select的sql语句修改一下,我的修改完成的如下:
get_categories_tree中修改
$sql = 'SELECT cat_id,cat_name,parent_id,is_show,cat_img ' .
'FROM ' . $GLOBALS['ecs']->table('category') .
"WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";
并增加
$cat_arr[$row['cat_id']]['cat_img'] = $row['cat_img'];
get_child_tree中修改
$child_sql = 'SELECT cat_id, cat_name, parent_id, is_show,cat_img ' .
'FROM ' . $GLOBALS['ecs']->table('category') .
"WHERE parent_id = '$tree_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";
并增加
$three_arr[$row['cat_id']]['cat_img'] = $row['category_img'];7、修改完上面的地方,清空网站缓存,然后刷新网站,经测试,数据库cat_img 字段已经能够上传图片了。
Dcr163的博客
http://dcr163.cn/404.html(转载时请注明本文出处及文章链接)