php - CakePHP 2.3.0 中 Form->postLink 中的多个参数

标签 php cakephp cakephp-2.3

是否可以使用 FormHelper 的方法 postLink 将多个参数传递给 Controller ​​中的操作?

我没能通过使用 options 数组来做到这一点。文档中没有很好地指定该数组接受哪些值。

这是我尝试过的:

$this->Form->postLink($staffUser['User']['_name'], array(
           'action' => 'subscribe', 
           array('ticketId' => $ticket['Ticket']['id'], 'userId' => $staffUser['User']['id'])
));

我的订阅操作如下所示:

public function subscribe($ticketId, $userId = null){
    if ($this->request->is('post')) {
        //...
    }
}


更新


我刚刚注意到所提供的解决方案给我带来了另一个问题。现在,class 停止添加,就像之前我只使用一个参数时一样:

$this->Form->postLink($staffUser['User']['_name'], array(
       'action' => 'subscribe', 
       $ticket['Ticket']['id'], 
       $staffUser['User']['id'],
       array('class' => 'demo') //not beind added
));

最佳答案

postLink 采用与 create 方法相同的形式获取其 URL 条目。参数不需要键,将它们按顺序放在操作键/值之后。

其他选项需要放在第三个参数中 - 您可以将选项数组作为 url 数组的附加条目。

$this->Form->postLink($staffUser['User']['_name'], array(
       'action' => 'subscribe', 
       $ticket['Ticket']['id'], 
       $staffUser['User']['id']
    ),
    array(
      'class' => 'demo'
    )
);

在此处查看 FormHelper::create 的选项: http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html

关于php - CakePHP 2.3.0 中 Form->postLink 中的多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26299297/

相关文章:

php - 如何为调用创建get方法

php - 有两个同名 HTTP GET 参数时的行为

CakePHP 链接在同一页面中

php - CakePHP 2.x 在 CSS 中使用 PHP

php - CakePHP 2.3 - 单元测试用户登录

PHP无效字符错误

php - 如果页面内容混合了 php、html、css 和 javascript/jquery...并且文件扩展名是 php,要设置什么内容类型?

php - 将 Wordpress Post 与 Cakephp3 集成

cakephp - 如何在Cakephp中使用帮助程序和组件中的常用功能

Cakephp在组件中加载Appcontroller方法