More information about this topic
Reset database
 | 
CTextHightlighter
You may input the text below and choose the language to see the highlighting difference :





Result :


echo "hello";

protected/modules/UiModule/views/ui_other/text_highlighter.php


echo CHtml::beginForm();
echo 'You may input the text below and choose the language to see the highlighting difference : <br/>';
echo CHtml::dropDownList('language',$language,$listLanguage);
echo "<br/>";

echo CHtml::checkBox('show-line-numbers',$showLineNumbers);
echo CHtml::label("Line Number", 'show-line-numbers');
echo "<br/>";

echo CHtml::textArea('code',$code,array('rows'=>10,'cols'=>80));
echo "<br/>";
echo CHtml::submitButton();
echo CHtml::endForm();

echo "<br/><br/>";
echo "<h3>Result :</h3>";
echo "<hr/>";
$this->beginWidget('system.web.widgets.CTextHighlighter',array(
	'language'=>$language,
	'showLineNumbers'=>$showLineNumbers,
));
echo $code;
$this->endWidget();

protected/modules/UiModule/controllers/Ui_otherController.php

	public function actionTextHighlighter(){

		$code = 'echo "hello"; '; //default code
		$language = 'php'; //default text
		$showLineNumbers = false;

		if (isset($_POST['code']))
			$code = $_POST['code'];

		if(isset($_POST['language']))
			$language = $_POST['language'];

		if(isset($_POST['show-line-numbers']))
			$showLineNumbers= true;

		//list currently available language that CTextHighlighter support
		$listLanguage = array(
			'php'=>'PHP',
			'sql'=>'SQL',
			'xml'=>'XML',
			'abap'=>'ABAP',
			'cpp'=>'C++',
			'css'=>'CSS',
			'diff'=>'DIFF',
			'dtd' => 'DTD',
			'html'=>'HTML',
			'java'=>'Java',
			'javascript'=>'Javascript',
			'mysql'=>'MySQL',
			'perl'=>'Perl',
			'python'=>'Python',
			'ruby'=>'Ruby',
		);

		$this->render('text_highlighter', array(
			'code'=>$code,
			'language'=>$language,
			'showLineNumbers'=>$showLineNumbers,
			'listLanguage'=>$listLanguage));
	}
References
Fork me on GitHub