2013-04-30 68 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