Applying markdown and HTML
When we create web applications, we will certainly have to deal with creating content. Of course, we can create it with pure text or HTML, but text is often too simple and HTML is too complex and insecure. That is why special markup languages, such as BBCode, Textile, and markdown are used.
In this recipe, we will learn how to create a model that will automatically convert markdown to HTML when it is being saved.
Getting ready
Create a new application by using
yiic webappas 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
postas follows:DROP TABLE IF EXISTS `post`; CREATE TABLE IF NOT EXISTS `post` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `title` VARCHAR(255) NOT NULL, `text` TEXT NOT NULL, `html` TEXT NOT NULL, PRIMARY KEY (`id`) );
Generate the
Postmodel using Gii.
How to do it...
Open the
protected/models/Post.phpfile...