Quick Guide to the Yii Framework: basic app development

(Updated on 7/9/2012)

Basic Yii App Dev

Install Yii

  1. Download Yii.
  2. Unpack Yii into server.

Note: Yii doesn’t need to be installed in htdocs.

Set up a new application/project

  1. Open the command line editor.
  2. Change the directory to %<Yii root dir>/framework.
  3. Type the following (<WebRoot> = main web folder, <appfolder> = folder where you’ll keep your apps: webapp <WebRoot>/<appfolder>
  4. Open your browser and go to http://<hostname>/<appfolder> to test the app.

Note: Does NOT work on a mapped drive on Windows, due to the hard-mapped location of XAMPP in the yiic.bat file.

Configure database (for MySQL setup)

  1. Create database in MySQL.
  2. Open <appfolder>/protected/config/main.php in text editor and edit “db” string.
  3. Also uncomment the MySQL connection, and comment out the SQLite connection in the main.php file.
  4. Create tables in database using MySQL.

Configure gii

  1. Open <appfolder>/protected/config/main.php and edit “gii” string (pun intended).
  2. Browse http://<hostname>/<appfolder>/index.php?r=gii and enter password (gii string).

Generate model

  1. Click Model Generator link.
  2. Enter datatable and model info.
  3. Press Preview and Generate buttons.
  4. Take note of the Model name, and make sure to follow the uppercase letters if any.

Generate codes

  1. Browse http://<hostname>/<appfolder>/index.php?r=gii
  2. Enter model (same as the one you noted in the Generate Model steps) and controller ID info.
  3. Press Preview and Generate buttons.

Access pages

Browse http://<hostname>/<appfolder>/index.php?r=<model> and test CRUD operations.

(end of quick start)

Once you are ready to customize the app, I advise you to go through the Yii Blog System tutorial to get a feel of how the codings are modified.