使用CakePHP的HTML / Form Helpers创建带有链接的按钮 [英] Creating buttons with links using CakePHP's HTML/Form Helpers

查看:143
本文介绍了使用CakePHP的HTML / Form Helpers创建带有链接的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to convert a link into a button using CakePHP Helpers.

使用 $ this-> Html-> link )我可以使用array()来包括'action'=> '查看'。 $ user ['User'] ['id'] ,但我不知道如何使用 $ this-> Form-> / code>。

With $this->Html->link() I am able to use an array() to include 'action' => 'view' . $user['User']['id'], but I am not sure how to include this when using $this->Form->button() instead.

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

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



我的解决方案



允许我添加'action'=> '查看'。 $ user ['User'] ['id']

使用 $ this-> Form-& button()

echo $this->Form->button('Click me', array(
    'type' => 'button',
    'onclick' => 'location.href=\'/rentmyride/users/index/\';',
    ));

使用< input> / p>

Using <input> tag:

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

使用< button> / p>

Using <button> tag:

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


推荐答案

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

HTML5 buttons have a formaction attribute for this use. Of course this works only in modern browsers

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

这篇关于使用CakePHP的HTML / Form Helpers创建带有链接的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆