我在整个页面中使用这个$categories
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributetoSelect('*')
->addAttributetoFilter('level',2)
->addisActiveFilter()
->addAttributetoSort('position');
foreach($categories as $cat) {$children=$cat->getChildrenCategories();}
选项1
//option 1
$children = $category->getChildren();
foreach(explode(',', $children) as $child):
$sub = Mage::getModel('catalog/category')->load($child);
$sub->getName() // this return ok, name show up
$sub->getimageUrl() // this return ok, image show up
选项2工作但由于某种原因无法获取图像URL.
//option 2
$children = $category->getChildrenCategories();
foreach($children as $sub):
$sub->getName() // this return ok, name show up
$sub->getimageUrl() // this return empty, image NOT show up so is other attribute beside name.
谁能解释一下这个区别?我将如何选择2来解决这个问题
解决方法:
基本上,当我们使用getChildrenCategories()函数时,只从类别字段集合中检索了几个字段 – > url_key,name,all_children,is_anchor.
你可以在类Mage_Catalog_Model_Resource_Category上看到它.如果想从函数中获取tget图像url那么只需添加addAttributetoFilter(‘image’)
$collection = $category->getCollection();
$collection->addAttributetoSelect('url_key')
->addAttributetoSelect('name')
->addAttributetoSelect('all_children')
->addAttributetoSelect('is_anchor')
->setorder('position', Varien_Db_Select::sql_ASC)
->joinUrlRewrite()
->addAttributetoFilter('is_active', 1)
->addIdFilter($category->getChildren())
->addAttributetoSelect('image');
foreach($category as $eachChildCat){
if ($image = $eachChildCat->getimage()) {
$url = Mage::getBaseUrl('media').'catalog/category/'.$image;
}
}
$eachChildCat-> getimage()不起作用然后使用$eachChildCat-> getResource() – > getimage()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。