1

In Zend Framework, I have one controller

class TestController extends Zend_Controller_Action
{

    public function indexAction()
    {

    }

    public function getResultByID( $id )
    {
        return $id;
    }

}

How can I call the function getResultByID in index.phtml ?

4

6 回答 6

6

第一的:

public function indexAction()
{
  $this->view->controller = $this
}

在您的视图脚本中:

<html><title><?php echo $this->controller->getResultByID($this->id); ?></title></html>
于 2012-10-19T16:06:49.850 回答
1

通过使用 Action View Helper :

http://framework.zend.com/manual/1.12/en/zend.view.helpers.html#zend.view.helpers.initial.action

于 2012-10-21T12:36:08.213 回答
0

如果indexAction执行了,您可以从那里调用它:

public function indexAction()
{
    $this->getResultByID( (int) $_REQUEST['id'] );
}
于 2012-10-19T09:46:51.697 回答
0
  public function getResultByID( $id )
  {
               return $id;
  }

而不是上面的代码你可以使用

  public function getResultByID( $id )
    {
         this->view->id=$id;
         this->render('index.phtml');
     }

那么您可以使用 index.phtl 中 id 的值作为this->id

于 2012-10-19T11:27:18.877 回答
0

试试这个代码我认为这是最好的选择

public function indexAction()
    {
       $this->view->assign('id' => $this->getResultByID($this->_request->getParam('id', null)))
    }

    public function getResultByID( $id = null )
    {
        return $id;
    }

并在视图中:回声$this->id

于 2012-10-19T11:20:42.417 回答
0

在您的 indexAction 方法中,以数组形式返回 getResultByID 方法。

控制器:

public function indexAction()
{
    return array(
       'getResult' => $this->getResultByID($id),
    );
}

public function getResultByID($id)
{
    return $id;
}

问题是你从哪里得到 $id。无论如何,在这样的变量中调用 getResult 字符串。

看法:

echo $getResult;

就是这样。

于 2016-02-29T09:49:08.430 回答