In this section, we describe how to create a skeleton application that will serve as our starting point. For simplicity, we assume that the document root of our Web server is
/wwwroot and the corresponding URL is
We first install the Yii framework. Grab a copy of the Yii release file (version 1.0.3 or above) from www.yiiframework.com and unpack it to the directory
/wwwroot/yii. Double check to make sure that there is a directory
Tip: The Yii framework can be installed anywhere in the file system. Its
frameworkdirectory contains all framework code and is the only directory needed when deploying an Yii application. A single installation of Yii can be used by multiple Yii applications.
After installing Yii, open a browser window and access the URL
http://www.example.com/yii/requirements/index.php. It shows the requirement checker provided in the Yii release. Make sure our Web server and PHP installation reaches the minimal requirement by Yii. In particular, we should enable both the
pdo_sqlite PHP extensions which are required by our blog application to access the SQLite database.
We then use the
yiic tool to create a skeleton application under the directory
yiic tool is a command line tool provided in the Yii release. It can be used to generate code for certain tasks.
Open a command window and execute the following command:
% /wwwroot/yii/framework/yiic webapp /wwwroot/blog Create a Web application under '/wwwroot/blog'? [Yes|No]y ......
Tip: In order to use the
yiictool as shown above, the CLI PHP program must be on the command search path. If not, the following command may be used instead:path/to/php /wwwroot/yii/framework/yiic.php webapp /wwwroot/blog
To try out the application we just created, open a Web browser and navigate to the URL
http://www.example.com/blog/index.php. We shall see that our application has three fully functional pages: the homepage, the contact page and the login page.
In the following, we briefly describe what we have in this skeleton application.
We have an entry script file
/wwwroot/blog/index.php which has the following content:
$yii='/wwwroot/framework/yii.php'; $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();
This is the only script that Web users can directly access. The script first includes the Yii bootstrap file
yii.php. It then creates an application instance with the specified configuration and executes the application.
We also have an application base directory
/wwwroot/blog/protected. The majority of our code and data will be placed under this directory, and it should be protected from being accessed by Web users. For Apache httpd Web server, we place under this directory a
.htaccess file with the following content:
deny from all
For other Web servers, please refer to the corresponding manual on how to protect a directory from being accessed by Web users.
To help understand how Yii works, we describe the main workflow in our skeleton application when a user is accessing its contact page:
sitecontroller and the
sitecontroller in terms of a
SiteControllerinstance and then executes it;
SiteControllerinstance executes the
contactaction by calling its
actionContactmethod renders a view named
contactto the Web user. Internally, this is achieved by including the view file
/wwwroot/blog/protected/views/site/contact.phpand embedding the result into the layout file