我在創建Magento中的A-Z索引搜索時遇到了一些麻煩。我已經創建的代碼,但是,我得到一個「無效的方法...」錯誤:無效方法... str_replace_once(Array)
str_replace_once(Array ( [0] => & [1] => ? [2] => 127.0.0.1/mgn-default/electronics/cameras.html))
我不熟悉PHP,這裏是用於代碼:
<?php
$search_array = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','ALL');
/*Find if the URL already contains any querystring variable or not */
if (strstr($this->helper('core/url')->getCurrentUrl(), "&"))
{
$separator = '&';
}
else
{
$separator = '?';
}
?>
<div>
<p class="view-mode-list-bot">
<?php
$postData = Mage::app()->getRequest()->getParam('alpha');
foreach ($search_array as $search_array_value):
/*Clean the URL*/
if (strstr($this->helper('core/url')->getCurrentUrl(), "?"))
{
$new_Url = $this->str_replace_once('&','?',str_replace("?alpha=".trim($postData['alpha']),'',str_replace($separator."alpha=".trim($postData['alpha']),'',$this->helper('core/url')->getCurrentUrl())));
}
else
{
$new_Url = str_replace("?alpha=".trim($postData['alpha']),'',str_replace($separator."alpha=".trim($postData['alpha']),'',$this->helper('core/url')->getCurrentUrl()));
}
$alphaURL = $new_Url.$separator.'alpha='.$search_array_value;
?>
<a href="<?php echo $alphaURL; ?>" title="<?php echo $_label ?>" class="<?php echo strtolower($_code); ?> <?php if($search_array_value == $postData){ echo 'remove_under'; } ?>"><?php echo $search_array_value; ?></a>
<?php endforeach; ?>
</p>
任何意見和幫助將不勝感激,非常感謝。
你自己實現了'str_replace_once()'嗎?它是由Magento定義的,並且可以在周圍的對象中使用? – mario