CTextHighlighter 用於格式化顯示程式碼,目前支援語言:ABAP、CPP、CSS、DIFF、DTD、HTML、JAVA、JAVASCRIPT、MYSQL、PERL、PHP、PYTHON、RUBY、SQL、XML。可透過 showLineNumbers=true 顯示行號。
一個帶行號、一個不帶行號:
PHP code
<?php $this->beginWidget('CTextHighlighter', array('language' => 'PHP')); ?>
// include Yii bootstrap file
$yii = 'C:/yiiframework/yii.php';
defined('YII_DEBUG') or define('YII_DEBUG', true);
$config = dirname(__FILE__).'/protected/config/main.php';
require_once($yii);
Yii::createWebApplication($config)->run();
<?php $this->endWidget(); ?>
PHP code with Line Number
<?php $this->beginWidget('CTextHighlighter', array('language' => 'PHP', 'showLineNumbers' => 'true')); ?>
/**
* SiteController is the default controller to handle user requests.
*/
class SiteController extends CController {
public function actionIndex() {
$model = new DataModel();
if (!empty($_POST['DataModel'])) {
$model->attributes = $_POST['DataModel'];
if ($model->validate()) $success = true;
}
$this->render('index', array('model' => $model));
}
}
<?php $this->endWidget(); ?>
透過指定 language 種類(不區分大小寫)指明程式碼類型。
