PHP development framework YiiFramework tutorial (18) UI component TextHighlighter example
CTextHighlighter is used to format the display code. Currently, the supported Display languages include ABAP, CPP, CSS, DIFF, DTD, HTML, JAVA, JAVASCRIPT, MYSQL, PERL, PHP, PYTHON, RUBY, SQL, XML. the line number can also be displayed when the code is displayed. the line number is displayed through showLineNumbers = TRUE.
In this example, the PHP code is displayed, with a line number and without a line number:
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 mode
Defined ('II _ debug') or define ('II _ debug', true );
$ Config = dirname (_ FILE _). '/protected/config/main. php ';
// Remove the following line when in production mode
// Defined ('II _ debug') or define ('II _ 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 ();?>
Specify the type of the code to be displayed by specifying the language type (case insensitive.