- Yii Framework – Application Skeleton
- Yii Framework – Application Skeleton Continued
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:
- 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.
- The css directory: This is the default directory for placing the css files being used in your application.
- The images directory: This directory stores the images being used in the application.
- 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:
- commands: Stores all the console command class files.
- components: Stores application specific components. The components include the helpers, widgets etc.
- config: Stores the configuration used by the application. For example, the DB configuration is defined inside this directory.
- controllers: The application controller files are stored here.
- lib: Contains the application specific third-party libraries.
- models: Stores the models required by the application.
- runtime: Stores any dynamically generated files.
- view: The application view files are stored here.
- 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.
- 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.
- 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.
- 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.