0

こんにちは、phtml からブロックに値を渡す方法は?

以下は私のコードです: 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);

それは動かなかった。

4

1 に答える 1

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());
}
于 2013-04-30T04:25:00.697 に答える