Yii Framework Forum: Button with link to controller action - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Button with link to controller action Rate Topic: -----

#1 User is offline   rulmonroy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 29-March 11

Posted 11 May 2011 - 11:48 PM

Hello:

I have a register action in my site to allow the guest user to create a new account for him.

Also I have a button in my index page with a link to the register action and that's where my problem begins. I tried with this:

<?php echo CHtml::button('Register', array('submit' => array('site/register'))); ?>


When I click the button nothing happens. I also tried with a link:

<?php echo CHtml::link('LinkText',array('site/register'),array('class'=>'btn_registro')); ?>


And it works perfectly but... I want a button !! hehe

I'd appreciate any help please. :S
0

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 12 May 2011 - 01:41 AM

Just use a link and style it as a button. Buttons worls properly only in forms, you should create a form with action the action you want, and put the button in the form.

A better approach is to use links, using the background you can style the link as a button, and even better.
0

#3 User is offline   _Stan_ 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 18-January 13

Posted 23 January 2013 - 02:51 PM

For those who may be interested in implementing the same behaviour, I'm just faced the same problem and solved it with the following code:

CHtml::button('Title', array('onclick' => 'js:document.location.href="controller/action"'));


Works for me.
2

#4 User is offline   Igor Savinkin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 30-July 13

Posted 07 August 2013 - 12:59 AM

View Postrulmonroy, on 11 May 2011 - 11:48 PM, said:

Hello:

I have a register action in my site to allow the guest user to create a new account for him.

Also I have a button in my index page with a link to the register action and that's where my problem begins. I tried with this:

<?php echo CHtml::button('Register', array('submit' => array('site/register'))); ?>


When I click the button nothing happens. I also tried with a link:

<?php echo CHtml::link('LinkText',array('site/register'),array('class'=>'btn_registro')); ?>


And it works perfectly but... I want a button !! hehe

I'd appreciate any help please. :S

0

#5 User is offline   Igor Savinkin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 30-July 13

Posted 07 August 2013 - 01:01 AM

Inside the referrence in a button you add
index.php?r=
before a controller/action. Like this:
js:document.location.href="index.php?r=controller/action"

0

#6 User is offline   Shahcheraghean 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 478
  • Joined: 12-December 12
  • Location:Mashhad, IRAN

Posted 07 August 2013 - 01:51 AM

Also you can use CHtml::linkButton()
www.shgn.ir
www.shgn.ir/yii-framework/
yii2.swsco.ir
In a world without any fences or walls,Who needs Gates or Windows!
0

#7 User is offline   Andrea.p 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 13-September 13

Posted 21 September 2013 - 03:27 AM

View Post_Stan_, on 23 January 2013 - 02:51 PM, said:

For those who may be interested in implementing the same behaviour, I'm just faced the same problem and solved it with the following code:

CHtml::button('Title', array('onclick' => 'js:document.location.href="controller/action"'));


Works for me.


Thanks!It works, but ignore all $_GET data, you have insert it like this:

<?php echo CHtml::button('Title', array('onclick' => 'js:document.location.href="index.php?r=controller/action&id='.$model->id.'"')); ?>


istead of:
<?php echo CHtml::link('Title', array('controller/action', 'id'=>$model->id)); ?>

0

#8 User is offline   reburg 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 15-January 13

Posted 11 September 2014 - 05:40 AM

View Postzaccaria, on 12 May 2011 - 01:41 AM, said:

Just use a link and style it as a button. ...

A better approach is to use links, using the background you can style the link as a button, and even better.

Please can you help me: :rolleyes:
How to style a link as a button in Yii?
Greetings from Austria
Ferdinand
0

#9 User is offline   Bizley 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 189
  • Joined: 29-July 14

Posted 11 September 2014 - 05:55 AM

Bootstrap style:

    background-image: none;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    display: inline-block;
    font-size: 14px;
    font-weight: normal;
    line-height: 1.42857;
    margin-bottom: 0;
    padding: 6px 12px;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    background-color: #000;
    color: #fff;
    text-decoration: none;


Create a css class with the above and use it on link.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users