CTextHighlighter is used to format the display code. The currently supported display languages are ABAP, CPP, CSS, DIFF, DTD, HTML, JAVA, JAVASCRIPT, MYSQL, PERL, PHP, PYTHON, RUBY, SQL, XML, when displaying the code. Line numbers can also be displayed, turning on line number display via showLineNumbers=TRUE.
This example displays PHP codes, one with line numbers and one without line numbers:
PHP code beginWidget('CTextHighlighter',array('language'=>'PHP')); ?> // include Yii bootstrap file//require_once(dirname(__FILE__).'/../../framework/yii.php');$yii='C:/yiiframework/yii.php'; // remove the following line when in production modedefined('YII_DEBUG') or define('YII_DEBUG',true); $config=dirname(__FILE__).'/protected/config/main.php'; // remove the following line when in production mode // defined('YII_DEBUG') or define('YII_DEBUG',true); require_once($yii);Yii::createWebApplication($config)->run();endWidget(); ?> PHP code with Line Number beginWidget('CTextHighlighter',array('language'=>'PHP','showLineNumbers'=>'true')); ?> /*** SiteController is the default controller to handle user requests. */class SiteController extends CController { /*** Index action is the default action in a controller.*/ public function actionIndex(){ $model=new DataModel(); if(!emptyempty($_POST[DataModel])){$model->attributes=$_POST[DataModel]; if($model->validate()) $success=true;} $this->render('index', array('model' => $model,));}}endWidget(); ?>
Indicate the type of code to be displayed by specifying the type of language (not case-sensitive).
The above is the content of the PHP development framework Yii Framework tutorial (18) UI component TextHighlighter example. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!