- 1 第一个应用 Hello World
- 2 Yii Web 应用基础
- 3 为应用添加日志
- 4 Hangman 猜单词游戏实例
- 5 URL 管理
- 6 CComponent 组件
- 7 使用 CHtml 创建 Form
- 8 使用 FormModel
- 9 UI 组件 Widget 概述
- 10 UI 组件 自定义组件
- 11 UI 组件 ActiveForm 示例
- 12 UI 组件 ClipWidget 示例
- 13 UI 组件 ContentDecorator 示例
- 14 UI 组件 MaskedTextField 示例
- 15 UI 组件 MultiFileUpload 示例
- 16 UI 组件 StarRating 示例
- 17 UI 组件 TabView 示例
- 18 UI 组件 TextHighlighter 示例
- 19 UI 组件 TreeView 示例
- 20 UI 组件 Captcha 示例
- 21 UI 组件 自定义 Captcha 示例
- 22 UI 组件 Zii 组件简介
- 23 数据库-概述
- 24 数据库-DAO 示例
- 25 数据库-Query Builder 示例
- 26 数据库-Active Record 示例
- 27 数据库-关联 Active Record 示例
- 28 Data Provider 简介
- 29 Zii 组件-Menu 示例
- 30 Zii 组件-ListView 示例
- 31 Zii 组件-DetailView 示例
- 32 Zii 组件-GridView 示例
- 33 Zii 组件-Accordion 示例
- 34 Zii 组件-AutoComplete 示例
- 35 Zii 组件-Button 示例
- 36 Zii 组件-DatePicker 示例
- 37 Zii 组件-Dialog 示例
- 38 Zii 组件-ProgressBar 示例
- 39 Zii 组件-Slider 示例
- 40 Zii 组件-SliderInput 示例
- 41 Zii 组件-Tabs 示例
- 42 Zii 组件-Draggable 示例
- 43 Zii 组件-Droppable 示例
- 44 Zii 组件-Resizable 示例
- 45 Zii 组件-Selectable 示例
- 46 Zii 组件-Sortable 示例
- 47 主题 Theme 示例
- 48 多国语言示例
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
18 UI 组件 TextHighlighter 示例
CTextHighlighter 用来格式化显示代码,目前支持显示的语言有 ABAP, CPP, CSS, DIFF, DTD, HTML, JAVA, JAVASCRIPT, MYSQL, PERL, PHP, PYTHON, RUBY, SQL, XML,显示代码时也可以显示行号,通过 showLineNumbers=TRUE 打开行号显示。
本例显示 PHP 代码,一个带行号,一个不带行号:
PHP code <!--?php $this--->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('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(); <!--?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 { /** * Index action is the default action in a controller. */ 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 的种类(不区分大小写) 指明需显示代码的种类。
图片 18.1 picture18.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论