Yii Framework – Application Skeleton Continued

This entry is part 2 of 2 in the series Starting Yii Framework

In the concluding section of the first post of Yii Application skeleton, we used the webapp command to generate the application skeleton. The application skeleton is the way the framework expects the developers to organize their code into different files ad directories. The framework would expect view files to be saved in a certain directory (usually a directory titled view in the application root of the framework). In addition, for a particular view, the framework looks for a certain filename in the view directory.

Going back to the webapp command we executed

Path/to/webroot/:>   ./yii/framework/yiic webapp test

This command creates a web application skeleton in the test directory of the webroot. Let’s see what directory structure the webapp command created for us.

The command creates five directories and two files under the test directory:

  1. The assets directory: The directory is meant for publishing resource files. This folder is meant to provide resolution of the resource naming conflicts. A simple standalone web application can keep the resources (css, js, images) in a unified location in the webroot. But, for an enterprise application running various modules, the resource naming conflicts may arise. For example, two modules may be using CSS files with same name but having different styling rules defined in them.
    The CAssetManager package of Yii can take modules resource files and automatically publishes them to the assets directory. The publishing is done on demand; when the web application needs those resources for the first time. At that time, those required resources are published to the assets directory. In the course of publishing, the resources gets a unique name; in fact unique path to be precise.
  1. The css directory: This is the default directory for placing the css files being used in your application.
  1. The images directory: This directory stores the images being used in the application.
  1. The protected directory: This is the directory that stores the application code files. This directory contains sub-directories for views, controllers, models etc. The important among the sub-directories are:
    1. commands: Stores all the console command class files.
    2. components: Stores application specific components. The components include the helpers, widgets etc.
    3. config: Stores the configuration used by the application. For example, the DB configuration is defined inside this directory.
    4. controllers: The application controller files are stored here.
    5. lib: Contains the application specific third-party libraries.
    6. models: Stores the models required by the application.
    7. runtime: Stores any dynamically generated files.
    8. view: The application view files are stored here.
    9. extensions: The pre-built extensions are stored in this directory.  For example, you might want to use the toexcel extension to export data to excel files.
  1. The themes directory: The enterprise applications may need separate themes/UI for different modules or sections of the application. This directory stores the theme files.
  1. The index.php file: This file is the entry point to the application. This is the bootstrap file of every Yii application. Every call to any web page within the application comes to this file.
  1. The index-test.php file: Yii provides this separate file, which acts as the entry point for the functional testing.

You can leverage on the skeleton generated by the webapp command of yiic. The default directories can be replaced or renamed by suitably modifying the configuration.

In the coming days, we will continue to explore other useful stuff related to Yii framework.

Series Navigation<< Yii Framework – Application Skeleton