2015-08-20 36 views
0

雖然使用下面的代碼,但我得到這樣的錯誤 解析錯誤:在C:\ wamp \ www \ magento3 \ app \ code \ local \ Envato \ Recentproducts \ Block \ Recentproducts.php中第7行在下面的php代碼中解析錯誤

<?php 
// app/code/local/Envato/Recentproducts/Block/Recentproducts.php 
class Envato_Recentproducts_Block_Recentproducts extends Mage_Core_Block_Template { 
    public function getRecentProducts() { 
    // call model to fetch data 
    $arr_products = array(); 
    $products = Mage::getModel("recentproducts/recentproducts")­>getRecentProducts(); 

    foreach ($products as $product) { 
     $arr_products[] = array(
     'id' => $product->getId(), 
     'name' => $product­>getName(), 
     'url' => $product­>getProductUrl(), 
    ); 
    } 

    return $arr_products; 
    } 
} 
+1

看*真的*關閉在那一行。字符的字符。 –

+0

仔細檢查您的代碼。看起來你有一些unicode發生在這裏或一些無法識別的字符。 –

+0

您使用哪個編輯器進行編碼? –

回答

1

似乎有某種類型的連字符,看起來像一個普通的-,但並非如此。

我試圖找出哪個字符是,但無法。

我用我的鍵盤-取代了所有這些。

旁註:這裏發生了一件很奇怪的事情。你的代碼沒有顯示缺少的連字符,但是當我複製/粘貼它時,它們出現在我的編輯器中。

如果你進入Stack的「編輯模式」爲see for yourself-as per original post,連字符就在那裏。

  • 有人可以解釋這一點嗎?我無法弄清楚。 (模糊地帶)。

這裏是重寫,這應該工作。

重要:(複製/粘貼下面的代碼,不修改現有的代碼)

<?php 
// app/code/local/Envato/Recentproducts/Block/Recentproducts.php 
class Envato_Recentproducts_Block_Recentproducts extends Mage_Core_Block_Template { 
    public function getRecentProducts() { 
    // call model to fetch data 
    $arr_products = array(); 
    $products = Mage::getModel("recentproducts/recentproducts")->getRecentProducts(); 

    foreach ($products as $product) { 
     $arr_products[] = array(
     'id' => $product->getId(), 
     'name' => $product->getName(), 
     'url' => $product->getProductUrl(), 
    ); 
    } 

    return $arr_products; 
    } 
} 

另一個奇怪的事情;連字符不能在編輯模式下顯示,並顯示爲

$product>getName 
$product>getProductUrl() 

但複製時/粘貼,就顯示爲:

$product->getName 
$product->getProductUrl() 
  • TBH,我來說,我完全莫名其妙。
  • 如果有人有解釋,請隨時編輯和/或評論。
  • OP使用Notepad ++作爲代碼編輯器。
+1

明白了,我只是刪除了那些連字符,並從鍵盤上再次放置它。現在它工作正常。謝謝... –

+0

@RajMalhotra不客氣Raj,我很高興我們能夠解決這個問題,*歡呼聲* –