If you are posting code, be it a company's internal wiki or a public developer's blog, it is always better to have the syntax highlighted, so users who read the code will feel comfortable. Yii has PEAR's Text_Highlighter
code-highlighting class bundled. It is used to highlight Yii definitive guide examples, and we can use it to do the same for our application.
In this recipe, we will create a simple application that will allow for adding, editing, and viewing code snippets.
Create a new application by using
yiic webapp
as described in the official guide at the following URL:http://www.yiiframework.com/doc/guide/en/quickstart.first-app
Set up a database connection and create a table named
snippet
as follows:CREATE TABLE `snippet` ( `id` int(11) unsigned NOT NULL auto_increment, `title` varchar(255) NOT NULL, `code` text NOT NULL, `html` text NOT NULL, `language` varchar(20) NOT NULL, PRIMARY KEY (`id`) );
Generate a
Snippet
model by using...