14

Zend ビュー ヘルパーには、ルーティング テーブルに基づいて URL を出力するための関数 url() があります。

$this->url(array('controller' => 'comments', 'action' => 'add')

コントローラーで同じことを行うにはどうすればよいですか? 特に、標準の URL ではなくコントローラー/アクション構文を使用して、Zend フォームのアクション URL を設定したいと考えています。

$form = new Zend_Form;
$form->setMethod('post')->setAction( $this->url(array('controller' => 'comments', 'action' => 'add')) );
4

4 に答える 4

23

これにはアクションヘルパーがあります:Zend_Controller_Action_Helper_Url。アクションコントローラ内では、次を使用してアクセスできます。

$this->_helper->url($action [, $controller [, $module [, $params]]]);

また:

$this->_helper->url->url(array(...));

または、ビューヘルパーを使用することもできます。

$this->view->url(...);
于 2009-11-05T14:20:06.203 に答える
3

私は実際にこれだけが機能することを発見しました:

// in your form
public function init()
{
    $router = Zend_Controller_Front::getInstance()->getRouter();
    $url = $router->assemble(
        array(
            'paramterName0' => 'parameterValue0',
            'paramterName1' => 'parameterValue1',
        ),
        'routeName'
    );

    $this->setAction($url);
    ...
}
于 2011-04-10T11:01:01.880 に答える
2

次のコードがうまくいくように見えるので、私自身の質問に答えることができました:-

$form = new Zend_Form;
$form->setMethod('post')->setAction( $this->getHelper('url')->url(array('controller' => 'index', 'action' => 'add')) );
于 2009-11-05T14:18:35.910 に答える