생산자

Creating Your First Yii Application

2013-11-08 14:26:44

To give you an initial experience with Yii, in this section we describe how to create your first Yii application. We will useyiic (command line tool) to create a new Yii application andGii (powerful web based code generator) to automate code creation for certain tasks. For convenience, we assume thatYiiRoot is the directory where Yii is installed, and WebRootis the document root of our Web server.

Run yiic on the command line as follows:

% YiiRoot/framework/yiic webapp WebRoot/testdrive

Note: When running yiic on Mac OS, Linux or Unix, you may need to change the permission of the yiic file so that it is executable. Alternatively, you may run the tool as follows,

% cd WebRoot
% php YiiRoot/framework/yiic.php webapp testdrive

This will create a skeleton Yii application under the directory WebRoot/testdrive. The application has a directory structure that is needed by most Yii applications.

Without writing a single line of code, we can test drive our first Yii application by accessing the following URL in a Web browser:

http://hostname/testdrive/index.php

As we can see, the application has four pages: the homepage, the about page, the contact page and the login page. The contact page displays a contact form that users can fill in to submit their inquiries to the webmaster, and the login page allows users to be authenticated before accessing privileged contents. See the following screenshots for more details.