2013-10-05 28 views
0

控制器视图。我已经使用以下功能在前端布局FIEL finder.xml indexController的负载控制器功能块和从块到.phtml

public function viewAction($string){ 
$stro = $this->getRequest()->getParams('key'); 
if($stro != null){ 
    $model = Mage::getModel('finder/finder'); 
$collection = $model->getCollection()->addFieldToFilter('companyname', $stro); 

$this->getResponse()->setBody($block->toHtml()); 
    } 
$this->loadLayout(); 
    $this->renderLayout(); 

我称follwing代码;

<finder_index_view> 
<reference name="content"> 
<block type="finder/info" name="finder" template="finder/info.phtml" /> 
</reference> 
</finder_index_view> 

如何在info.phtml文件中显示此控制器函数的输出。

回答

0

第1步:控制器(IndexController.php)文件在索引控制器中,只需加载布局并进行渲染即可。

<?php 
class Abc_Example_IndexController extends Mage_Core_Controller_Front_Action 
{ 
    public function indexAction() 
    { 
     $this->loadLayout(); 
     $this->renderLayout(); 
    } 
} 
?> 

步骤2:布局(custom.xml)文件将下面给定的代码放在模块的布局文件中。

<?xml version="1.0"?> 
<layout version="0.1.0"> 
    <example_index_index> 
     <reference name="content"> 
      <block type="example/collection" name="collection" template="example/collection.phtml" /> 
     </reference> 
    </example_index_index> 
</layout> 

这里是块码,你可以定义集合

<?php 
    class Abc_Example_Block_Collection extends Mage_Core_Block_Template 
    { 
     public function __construct() 
     { 
      parent::__construct(); 
      $stro = $this->getRequest()->getParams('key'); 
      if($stro != null){ 
      $model = Mage::getModel('finder/finder'); 
      $collection = $model->getCollection()->addFieldToFilter('companyname', $stro); 
      $this->setCollection($collection); 
     } 
    } 

,现在你可以访问此集合中info.phtml

<?php $collection = $this->getCollection(); ?> 

希望这将帮助你