Category: Yii Framework

Adding Composer Autoload to Yii Framework 1 and using PHPMarkdown

Using the database to manage blog content sucks, let’s use markdown to create a blog on yii framework 1.

Setting Up Composer Autoload

I’m assuming composer is already setup as per yii’s installation. You need to get the PHPMarkdown package with:

composer require michelf/php-markdown

The to make sure the classes from composer are autoloaded, add the following to yii’s index.php entry point.

// Add composer packages
$loader = require(__DIR__ . '/../vendor/autoload.php');
Yii::$classMap = $loader->getClassMap();

Now creating the simple blog post.

Creating a simple blog post with PHP Markdown in Yii Framework 1

So we will need to read the contents of a markdown file sitting on the server, preferably in a non public location like <root>/protected/data/blog/

So let us add that file:

## Yay

This is my first blog post

Now in the action of the BlogController that you will need to create, we need to read the file contents and then convert that to html with PHPMarkdown and then send that html to the view file.

$markdown=file_get_contents(dirname(__FILE__) . "/../data/blog/",'r');
$html = Markdown::defaultTransform($markdown);

$this->render('index', array('article' => $html));

The final step is showing the htmlified contents of the blog post in the view file index.php:


Source: Adding composer to yii stackoverflow

Setting up Yii Environment on your Server

How to Setup Yii on your Environment Server

1. Make Sure your vhost is setup correctly, with debian/ubuntu that is /etc/apache2/sites-available/sitename

Options FollowSymLinks -Indexes Includes
AllowOverride All

2. Set your include path in php.ini that is etc/php/apache2/php.ini

; UNIX: "/path1:/path2"
include_path = ".:/usr/share/library"

3. Download, get url from Yii Download Page


4. Unzip

tar -xzvf file.tar.gz

5. Change name, Set Permissions, Restart Apache:

mv yii-1.14e2938u123 yii
chown www-data:www-data yii/
chmod -R 755 yii/
service apache2 restart

6. Finally you still need to give the exact directory in index.php of the yii.php: