我该怎么做才能解决这个错误?
ERR(3):警告:在第79行的/app/design/adminhtml/default/default/template/canonical/canonical/edit/tab/header.phtml中为foreach()提供的参数无效
<?php if ( Mage::getSingleton('admin/session')->isAllowed('admin/global_search') ): ?>
<fieldset>
<legend>Search</legend>
<span id="global_search_indicator" class="autocomplete-indicator" style="display: none">
<img src="<?php echo $this->getSkinUrl('images/ajax-loader.gif') ?>" alt="<?php echo $this->__('Loading...') ?>" class="v-middle"/>
</span>
<?php $defSearch = $this->__('Global Record Search') ?>
<input id="global_search" name="query" type="text" class="input-text" value="<?php if(!empty($query)): ?><?php echo $query ?><?php else: ?><?php echo $defSearch ?><?php endif ?>" onfocus="if(this.value=='<?php echo $defSearch ?>')this.value=''; " onblur="if(this.value=='')this.value='<?php echo $defSearch ?>';" />
<div id="global_search_autocomplete" class="autocomplete"></div>
<script type="text/javascript">
new Ajax.Autocompleter(
'global_search',
'global_search_autocomplete',
'<?php echo $this->getUrl('adminhtml/index/globalSearch') ?>',
{
paramName:"query",
minChars:2,
indicator:"global_search_indicator",
updateElement:getSelectionId,
evalJSON:'force'
}
);
function getSelectionId(li) {
location.href = li.getAttribute('url');
}
</script>
</fieldset>
<?php endif; ?>
</div>
</div>
<?php if(Mage::getStoreConfig('advanced/modules_disable_output/FME_Canonical')==0) : ?>
<?php
$product_id = Mage::app()->getRequest()->getParam('id');
$_product = Mage::getModel('catalog/product')->load($product_id);
$selected = $_product->getData('fme_canonicalurl');
$catIds = $_product->getCategoryIds();
foreach ($catIds as $key )
{
$catCollection = Mage::getResourceModel('catalog/category_collection')
->addAttributeToFilter('entity_id', $key);
foreach($catCollection as $cat)
{
$dat[] = $cat->getId();
}
}
?>
<script type="text/javascript">
window.onload = function () {
if(categories = document.getElementById("fme_canonicalurl"))
{
var categories = document.getElementById("fme_canonicalurl");
var newOption = document.createElement('option');
newOption.text = "<?php echo $_product->getUrlPath() ?>";
newOption.setAttribute('value', "<?php echo $_product->getUrlPath() ?>");
categories.appendChild(newOption);
<?php
foreach ($dat as $value ) {
echo "var newOption = document.createElement('option');";
$_category = Mage::getModel('catalog/category')->load($value);
$url = $_product->getUrlPath($_category); ?>
newOption.text = "<?php echo $url ?>" ;
newOption.setAttribute('value', '<?php echo $url ?>');
categories.appendChild(newOption);
<?php
}
?>
function setSelectedIndex(s, v) {
for ( var i = 0; i < s.options.length; i++ ) {
if ( s.options[i].value == v ) {
s.selectedIndex = i;
return;
}
}
}
setSelectedIndex(categories,"<?php echo $selected?>");
}
}
答案 0 :(得分:0)
您的问题是您是在循环内将数据推送到HashLocationStrategy
数组中,但您尚未首先对其进行初始化。如果没有结果循环并且没有数据被推送到$dat
,那么当您稍后尝试循环$dat
时,它将被取消定义。
首先初始化它:
$dat