我试图获取产品图片,但是没有找到显示错误图像文件的magento
There has been an error processing your request
Image file was not found.
Trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Catalog/Helper/Image.php(166): Mage_Catalog_Model_Product_Image->setBaseFile(NULL)
#1 /Applications/XAMPP/xamppfiles/htdocs/whi/app/design/adminhtml/default/default/template/whi/brand/my_collections/brand_indi_collection_view.phtml(98): Mage_Catalog_Helper_Image->init(Object(Mage_Catalog_Model_Product), 'thumbnail')
#2 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Template.php(241): include('/Applications/X...')
#3 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('adminhtml/defau...')
#4 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#5 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Adminhtml/Block/Template.php(81): Mage_Core_Block_Template->_toHtml()
#6 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Adminhtml_Block_Template->_toHtml()
#7 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Text/List.php(43): Mage_Core_Block_Abstract->toHtml()
#8 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Text_List->_toHtml()
#9 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Abstract.php(637): Mage_Core_Block_Abstract->toHtml()
#10 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Abstract.php(581): Mage_Core_Block_Abstract->_getChildHtml('content', true)
#11 /Applications/XAMPP/xamppfiles/htdocs/whi/app/design/adminhtml/default/default/template/whohasitadmin/layout/admin.phtml(224): Mage_Core_Block_Abstract->getChildHtml('content')
#12 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Template.php(241): include('/Applications/X...')
#13 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('adminhtml/defau...')
#14 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#15 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Adminhtml/Block/Template.php(81): Mage_Core_Block_Template->_toHtml()
#16 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Adminhtml_Block_Template->_toHtml()
#17 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Model/Layout.php(555): Mage_Core_Block_Abstract->toHtml()
#18 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Controller/Varien/Action.php(390): Mage_Core_Model_Layout->getOutput()
#19 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/local/Whi/Brands/controllers/MycollectionController.php(358): Mage_Core_Controller_Varien_Action->renderLayout()
#20 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Whi_Brands_MycollectionController->individual_collection_viewAction()
#21 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('individual_coll...')
#22 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#23 /Applications/XAMPP/xamppfiles/htdocs/whi/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#24 /Applications/XAMPP/xamppfiles/htdocs/whi/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#25 /Applications/XAMPP/xamppfiles/htdocs/whi/index.php(90): Mage::run('', 'store')
#26 {main}
Error log record number: 1154029962119
这是我的控制器。
public function individual_collection_viewAction() {
$Params = $this->getRequest()->getParams();
$category = new Mage_Catalog_Model_Category();
$category->load($Params['id']);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
$data['products'] = $collection->load();
$this->loadLayout();
$block = Mage::app()->getLayout()->getBlock('mycollection_individual_view');
if ($block) {
$block->setData($data);
}
$this->renderLayout();
}
这是我的观点:
<?php
foreach ($data['products'] as $product) {
$productName = $product->getName();
$proimage = Mage::helper('catalog/image')->init($product, 'thumbnail');
//$productImage = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true) . "media/catalog/product" .$product->getImage();
?>
产品名称已成功获取但当我尝试获取图像时,未找到重新成像的图像。任何人都可以帮我解决这个问题。
答案 0 :(得分:3)
首先您需要验证在Magento管理员中选择基本,小图像和缩略图。
admin-&gt; catalog-&gt; manage product-&gt; product-&gt; image
然后使用
调用图像 <Grid>
<StackPanel>
<StackPanel Orientation="Horizontal">
<Button Content="◄" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Button Content="►" HorizontalAlignment="Right" VerticalAlignment="Top"/>
</StackPanel>
<Grid Height="245">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--Declaring Label-->
<DockPanel LastChildFill="False" Background="Yellow">
<Label Content="Left" Grid.Column="0" DockPanel.Dock="Left" />
</DockPanel>
<!--Splitter Code-->
<GridSplitter HorizontalAlignment="Right" VerticalAlignment="Stretch" Grid.Column="1" ResizeDirection="Columns"
Background="Black" ResizeBehavior="PreviousAndNext" Width="10"/>
<!--Declaring Label-->
<Label Content="Right" Grid.Column="2" Background="Pink"/>
</Grid>
</StackPanel>
</Grid>
或
$proimage = (string)Mage::helper('catalog/image')->init($product, 'thumbnail');//image,smallimage
修改强>
$proimage = Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getThumbnail()); //getSmallImage(), getImage()
答案 1 :(得分:0)
<?php
foreach ($data['products'] as $product) {
$product = Mage::getModel('catalog/product')->load($product->getId());
$productName = $product->getName();
$proimage = Mage::helper('catalog/image')->init($product, 'thumbnail');
?>