Creating buttons with links using CakePHP's HTML/Form Helpers

Viewed 27871

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

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.

Using $this->Html->link():

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

My Solutions

My solutions do not allow me to add 'action' => 'view' . $user['User']['id']

Using $this->Form->button():

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

Using <input> tag:

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

Using <button> tag:

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