Yii Framework Forum: Chtml::linkbutton Parameter - Yii Framework Forum

Jump to content

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

Chtml::linkbutton Parameter Rate Topic: -----

#1 User is offline   A.C. Arsyady 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 23-November 12

Posted 23 November 2012 - 05:16 AM

Sorry, couldn't find any thread discussing this. Hope this is one is good.

I got a question while using CHtml::linkButton. I'd like to generate a link which href refers to some URL. Here is the code:
<?php 
	echo CHtml::linkButton('Print', array(
		'href'=>array('print', $_GET),
		'submit'=>array('print', $_GET),
	));
?>


But somehow the generated link didn't point to the address. It always point to '#', so I checked the source code of CHtml class. I found this:
/**
 * Generates a link submit button.
 * @param string $label the button label
 * @param array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few special
 * attributes are also recognized (see {@link clientChange} and {@link tag} for more details.)
 * @return string the generated button tag
 * @see clientChange
 */
public static function linkButton($label='submit',$htmlOptions=array())
{
	if(!isset($htmlOptions['submit']))
		$htmlOptions['submit']=isset($htmlOptions['href']) ? $htmlOptions['href'] : '';
	return self::link($label,'#',$htmlOptions);
}


Looks like it always assign the link to '#', whatever the htmlOptions.
I managed to solve this by editing the source code to:
public static function linkButton($label='submit',$htmlOptions=array())
{
	if(!isset($htmlOptions['submit']))
		$htmlOptions['submit']=isset($htmlOptions['href']) ? $htmlOptions['href'] : '';
	// return self::link($label,'#',$htmlOptions);
	return self::link($label,$htmlOptions['submit'],$htmlOptions);
}


Is there any other solution to manage this (without editing the source code)?

Thanks in advance, and sorry for my bad English.
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