2013-04-30 69 views
0

嗨如何將價值從phtml傳遞到塊?Magento通過價值來阻止功能

下面是我的代碼: store.php

public function __construct($type1) 
    { 
     parent::__construct(); 
     $items = Mage::getModel('redemption/store')->getCollection() 
       ->addFieldToFilter('status', array('eq' => 1)) 
       ->addFieldToFilter('category', array('eq' => $type1)) 
       ->addAttributeToSort('mreward_required', 'asc'); 
     $this ->setCollection($items); 

    } 

index.phtml

$type1 = 'Celcom'; 
$items = $this->getCollection($type1); 

它沒有工作。

回答

0

爲什麼你想解析從phtml到塊的東西? phtml只是一個html代碼,所有的數據將被塊解析。但是,如果你仍然想這樣做(我認爲這是很奇怪的),你可以嘗試這樣的:

在您的PHTML:

$type = 'type'; 
$this->setType($type); 

//call a function so the block can get the type 
$this->parseTheDataToBlock(); 

而且在同一個區:

public function parseTheDataToBlock() { 
    //you will get the type here (from the phtml) 
    var_dump($this->getType()); 
} 
+0

我想要這樣做,是因爲我想打出類別的兌換產品基礎。這是更好的方法嗎? – 2013-04-30 04:56:52

+0

如果你想這樣做,你可以調用'$ this-> getCollection($ type)'並在塊'public function getCollection($ type){}'上重新定義'getCollection'函數。 – 2013-05-01 03:15:39