1

Zend Framework には、コントローラーが 1 つあります。

class TestController extends Zend_Controller_Action
{

    public function indexAction()
    {

    }

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

}

index.phtml で関数 getResultByID を呼び出すにはどうすればよいですか?

4

6 に答える 6

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
  public function getResultByID( $id )
  {
               return $id;
  }

上記のコードの代わりにuは使用できます

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

次に、index.phtlのidの値を次のように使用できます。this->id

于 2012-10-19T11:27:18.877 に答える
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 に答える
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そこから呼び出すことができます:

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