[ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 /** 3 * TLabel class file. 4 * 5 * @author Qiang Xue <qiang.xue@gmail.com> 6 * @link http://www.pradosoft.com/ 7 * @copyright Copyright © 2005 PradoSoft 8 * @license http://www.pradosoft.com/license/ 9 * @version $Id: TLabel.php 1397 2006-09-07 07:55:53Z wei $ 10 * @package System.Web.UI.WebControls 11 */ 12 13 /** 14 * TLabel class 15 * 16 * TLabel displays a piece of text on a Web page. 17 * Use {@link setText Text} property to set the text to be displayed. 18 * TLabel will render the contents enclosed within its component tag 19 * if {@link setText Text} is empty. 20 * To use TLabel as a form label, associate it with a control by setting the 21 * {@link setForControl ForControl} property. 22 * The associated control must be locatable within the label's naming container. 23 * If the associated control is not visible, the label will not be rendered, either. 24 * 25 * Note, {@link setText Text} will NOT be encoded for rendering. 26 * Make sure it does not contain dangerous characters that you want to avoid. 27 * 28 * @author Qiang Xue <qiang.xue@gmail.com> 29 * @version $Id: TLabel.php 1397 2006-09-07 07:55:53Z wei $ 30 * @package System.Web.UI.WebControls 31 * @since 3.0 32 */ 33 class TLabel extends TWebControl 34 { 35 private $_forControl=''; 36 37 /** 38 * @return string tag name of the label, returns 'label' if there is an associated control, 'span' otherwise. 39 */ 40 protected function getTagName() 41 { 42 return ($this->getForControl()==='')?'span':'label'; 43 } 44 45 /** 46 * Adds attributes to renderer. 47 * @param THtmlWriter the renderer 48 * @throws TInvalidDataValueException if associated control cannot be found using the ID 49 */ 50 protected function addAttributesToRender($writer) 51 { 52 if($this->_forControl!=='') 53 $writer->addAttribute('for',$this->_forControl); 54 parent::addAttributesToRender($writer); 55 } 56 57 /** 58 * Renders the label. 59 * It overrides the parent implementation by checking if an associated 60 * control is visible or not. If not, the label will not be rendered. 61 * @param THtmlWriter writer 62 */ 63 public function render($writer) 64 { 65 if(($aid=$this->getForControl())!=='') 66 { 67 if($control=$this->findControl($aid)) 68 { 69 if($control->getVisible(true)) 70 { 71 $this->_forControl=$control->getClientID(); 72 parent::render($writer); 73 } 74 } 75 else 76 throw new TInvalidDataValueException('label_associatedcontrol_invalid',$aid); 77 } 78 else 79 parent::render($writer); 80 } 81 82 /** 83 * Renders the body content of the label. 84 * @param THtmlWriter the renderer 85 */ 86 public function renderContents($writer) 87 { 88 if(($text=$this->getText())==='') 89 parent::renderContents($writer); 90 else 91 $writer->write($text); 92 } 93 94 /** 95 * @return string the text value of the label 96 */ 97 public function getText() 98 { 99 return $this->getViewState('Text',''); 100 } 101 102 /** 103 * @param string the text value of the label 104 */ 105 public function setText($value) 106 { 107 $this->setViewState('Text',$value,''); 108 } 109 110 /** 111 * @return string the associated control ID 112 */ 113 public function getForControl() 114 { 115 return $this->getViewState('ForControl',''); 116 } 117 118 /** 119 * Sets the ID of the control that the label is associated with. 120 * The control must be locatable via {@link TControl::findControl} using the ID. 121 * @param string the associated control ID 122 */ 123 public function setForControl($value) 124 { 125 $this->setViewState('ForControl',$value,''); 126 } 127 } 128 129 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |