TLinkButton creates a hyperlink style button on the page.
TLinkButton has the same appearance as a hyperlink. However, it is mainly
used to submit data to a page. Like {@link TButton}, you can create either
a submit button or a command button.
A command button has a command name (specified by
the {@link setCommandName CommandName} property) and and a command parameter
(specified by {@link setCommandParameter CommandParameter} property)
associated with the button. This allows you to create multiple TLinkButton
components on a Web page and programmatically determine which one is clicked
with what parameter. You can provide an event handler for
{@link onCommand OnCommand} event to programmatically control the actions performed
when the command button is clicked. In the event handler, you can determine
the {@link setCommandName CommandName} property value and
the {@link setCommandParameter CommandParameter} property value
through the {@link TCommandParameter::getName Name} and
{@link TCommandParameter::getParameter Parameter} properties of the event
parameter which is of type {@link \Prado\Web\UI\TCommandEventParameter}.
A submit button does not have a command name associated with the button
and clicking on it simply posts the Web page back to the server.
By default, a TLinkButton component is a submit button.
You can provide an event handler for the {@link onClick OnClick} event
to programmatically control the actions performed when the submit button is clicked.
Clicking on button can trigger form validation, if
{@link setCausesValidation CausesValidation} is true.
And the validation may be restricted within a certain group of validator
controls by setting {@link setValidationGroup ValidationGroup} property.
If validation is successful, the data will be post back to the same page.
TLinkButton will display the {@link setText Text} property value
as the hyperlink text. If {@link setText Text} is empty, the body content
of TLinkButton will be displayed. Therefore, you can use TLinkButton
as an image button by enclosing an <img> tag as the body of TLinkButton.
/** * Initializes the header cell. * * This method attempts to use {@link getHeaderRenderer HeaderRenderer} to * instantiate the header cell. If that is not available, it will populate * the cell with an image or a text string, depending on {@link getHeaderImageUrl HeaderImageUrl} * and {@link getHeaderText HeaderText} property values. * * If the column allows sorting, image or text will be created as * a button which issues <b>Sort</b> command upon user click. * * @param TTableCell the cell to be initialized * @param integer the index to the Columns property that the cell resides in. */ protected function initializeHeaderCell($cell, $columnIndex) { $text = $this->getHeaderText(); if (($classPath = $this->getHeaderRenderer()) !== '') { $control = Prado::createComponent($classPath); $cell->getControls()->add($control); if ($control instanceof \Prado\IDataRenderer) { if ($control instanceof IItemDataRenderer) { $item = $cell->getParent(); $control->setItemIndex($item->getItemIndex()); $control->setItemType($item->getItemType()); } $control->setData($text); } } else { if ($this->getAllowSorting()) { $sortExpression = $this->getSortExpression(); if (($url = $this->getHeaderImageUrl()) !== '') { $button = new TImageButton(); $button->setImageUrl($url); $button->setCommandName(TDataGrid::CMD_SORT); $button->setCommandParameter($sortExpression); if ($text !== '') { $button->setAlternateText($text); } $button->setCausesValidation(false); $cell->getControls()->add($button); } else { if ($text !== '') { $button = new TLinkButton(); $button->setText($text); $button->setCommandName(TDataGrid::CMD_SORT); $button->setCommandParameter($sortExpression); $button->setCausesValidation(false); $cell->getControls()->add($button); } else { $cell->setText(' '); } } } else { if (($url = $this->getHeaderImageUrl()) !== '') { $image = new TImage(); $image->setImageUrl($url); if ($text !== '') { $image->setAlternateText($text); } $cell->getControls()->add($image); } else { if ($text !== '') { $cell->setText($text); } else { $cell->setText(' '); } } } } }
/** * Instantiates the template. * It creates a {@link TLinkButton}. * @param TControl parent to hold the content within the template */ public function instantiateIn($parent) { $button = new TLinkButton(); $button->setID(TWizard::ID_SIDEBAR_BUTTON); $parent->getControls()->add($button); }
/** * Ensures that the anchor is rendered correctly when its Enabled property * changes in a callback * @param bool enabled */ public function setEnabled($value) { if (parent::getEnabled() === $value) { return; } parent::setEnabled($value); if ($this->getActiveControl()->canUpdateClientSide()) { if ($this->getEnabled(true)) { $nop = "javascript:;//" . $this->getClientID(); $this->getPage()->getCallbackClient()->setAttribute($this, 'href', $nop); $this->getActiveControl()->registerCallbackClientScript($this->getClientClassName(), $this->getPostBackOptions()); } else { $this->getPage()->getCallbackClient()->setAttribute($this, 'href', false); } } }