gpt4 book ai didi

cakephp - 使用 CakePHP 的 HTML/Form Helpers 创建带有链接的按钮

转载 作者:行者123 更新时间:2023-12-05 00:27:24 49 4
gpt4 key购买 nike

我想使用 CakePHP Helpers 将链接转换为按钮。

$this->Html->link()我可以使用 array() 来包含 'action' => 'view' . $user['User']['id'] ,但我不确定在使用 $this->Form->button() 时如何包含它反而。

使用 $this->Html->link() :

$this->Html->link('Click me', array(
'controller' => 'users',
'action' => 'view' . $user['User']['id']));

我的解决方案

我的解决方案不允许我添加 'action' => 'view' . $user['User']['id']
使用 $this->Form->button() :
echo $this->Form->button('Click me', array(
'type' => 'button',
'onclick' => 'location.href=\'/rentmyride/users/index/\';',
));

使用 <input>标签:
<input type="button" class="btn btn-primary" value="Click me" 
onclick="location.href='http://www.domain.com';">

使用 <button>标签:
<button class="btn btn-success" onclick="location.href='http://www.domain.com';">
Click me
</button>

最佳答案

HTML5 按钮具有用于此用途的 formaction 属性。当然,这只适用于现代浏览器

$this->Form->button(
'Click me',
array(
'formaction' => Router::url(
array('controller' => 'users','action' => 'view' . $user['User']['id'])
)
)
);

关于cakephp - 使用 CakePHP 的 HTML/Form Helpers 创建带有链接的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20740668/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com