2015-09-14 133 views
1

我有一个关于Zend控制器的信息,我想在index.php上的div上显示为菜单,标题为按钮,内容为内容本身。 我试图按照几个教程,但没有得到任何地方。 有人可以从如何从索引调用控制器的一些灯光?连接到Zend框架控制器

<?php 

class TabController extends Zend_Controller_Action 
{ 

public function init() 
{ 
    /* Initialize action controller here */ 
} 

public function indexAction() 
{ 
    // action body 
} 

public function tabcontentAction(){ 

    $this->_helper->viewRenderer->setNoRender(); 
    $this->_helper->layout()->disableLayout(); 


     $arr = array(array(Title => "Women", 
        Content => date("H:i:s") . " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris sem ligula, luctus et a 
(...) 
     ) 
     ); 

echo json_encode($arr); 
} 


} 

谢谢

回答

0

您可以创建一个返回数据的单独方法:

protected function getMyData() 
{ 
    $arr = array(
     array( 
      'Title' => "Women", 
      'Content' => date("H:i:s") . " Lorem ipsum dolor sit amet..", 
     ), 
    ); 
} 

然后在需要它的任何行动引用此方法:

public function indexAction() 
{ 
    $data = $this->getMyData(); 
    // now, do something with the @data 
} 

public function tabcontentAction() 
{ 
    $data = $this->getMyData(); 
    // now, do something with the $data 
}