簡體   English   中英

在Zend Framework 2中通過URL傳遞參數

[英]Pass parameters by URL in Zend Framework 2

我在使用Zend Framework中的URL傳遞參數時遇到麻煩。

例如,我有一個像這樣的控制器:

class MyController extends AbstractActionController {
    public function indexAction() { ... }
    public function updateAction($id) { ... }
}

我想通過以下URL訪問更新頁面: http : //example.com/mycontroller/update/1

那么如何將值1傳遞給控制器​​?

誰能幫我? 非常感謝。

順便說一句,我已經將默認路由器從

'route'    => '/[:controller[/:action]]'

'route'    => '/[:controller[/:action[/:id]]]',

但它仍然不起作用。 這是下面的錯誤消息。

Warning: Missing argument 1 for Module\\Controller\\MyController::updateAction() call in ...

我已經解決了問題!

您應該按以下方式更改功能:

public function updateAction()
{
    $paramName = $this->getEvent()->getRouteMatch()->getParam('id');

    // Do something with $paramName

    return array();
}

在Zend Framework2中有更多的方法來獲取參數: 如何在Zend Framework 2中訪問路由,發布,獲取等參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM