Yii Framework is vary strong and powerful PHP framework for robust applications. We can follow various YII topics in this discussion.
1) Create New YII Application:
Yii can support multiple applications with single instance of core framework.
So we can keep framework folder in any location. Just need to call framework/yii.php in application root index.php file as
When we can create application skeleton using command prompt, we don’t need to put above code system automatically write this. With command prompt we can fire following command,
PHP_INSTALL_DIRECTORY\php YII_FRAMEWORK_DIRECTORY\yiic webapp NEW_APPLICATION_DIRECTORY
We can easily understand this from following example,
C:\Users\Santanu>c:\xampp\php\php c:\xampp\htdocs\yii-1.1.10.r3566\framework\yiic webapp c:\xampp\htdocs\yiiapplication
Where ‘yiiapplication’ is new application which we want to create. Yiic is executable batch file which can run command webapp to create the application. Php is defined as php.exe which helps yiic to create application with php runtime.
2) Yii Application Structure:
Yii follows MVC model. In Yii skeleton application we can see assets, css, images, protected, themes directory.
Protected directory is most important directory for application. Which contain `config’, ‘controllers’, ‘models’, ‘views’, ‘extensions’ and ‘components’.
- Config directory stores application configuration related data.
- All controllers must store in `controllers` directory.
- All models stores in `model` directory.
If we don’t want to use theme for application we can store all view file in Views directory and we can get css, js, images from application root folder directories e.g. ’css`, ‘js’, ‘images’.
- Layouts directory stores design layouts like home layout, inner page layout etc.
- Site is a directory which name come from same named controller. It can contain view which can take care by site controller. For other controller we can see controller named directory in same location like ’site’ views.
- Extensions directory we can use for store extensions.
- Components directory we can use for store components.
Theme directory can be useful when we want to use theme(s) in application. So we can use themes directory for theming and can skip core view (application/protected/views), core css (application/css) and core images (application/images). We can use more than one theme so we have to put theme name as directory under themes folder and we can put directories like ‘views’, ‘css’, ‘js’, ‘images’.
View folder can contain layouts and view for controllers (actions).
- Layouts directory stores design layouts like home layout, inner page layout etc for the theme.
- Controllers actions can be stored as parallel folder with same name as controller without term controller.
- CSS directory stored css files which can useable by views of theme (application/themes/THEME_NAME/views).
- JS directory stored js files which can useable by views of theme (application/themes/THEME_NAME/views).
- Images directory stores images files which can useable by views of theme (application/THEME_NAME/views).
- View folder can contain layouts and view for controllers (actions).
- Assets stored various client side components like ’Jquery’, ‘Widget’, ‘Autocomplete’, ‘Tab’, ‘Tree’ etc. which are created by framework.
- CSS directory stored css files when application mostly using core views (application/protected/views).
- Images directory stores images when application mostly using core views (application/protected/views).
3) YII Application Working Path:
index.php under application root contain 1st line as framework file. e.g.
Second line it can include configuration file of the application like,
- In configuration file (application/protected/config/main.php) we can define, application base directory, startup controller (router), database type (MySQL/SQlite), database connection parameters, error file, theme name, GII configuration, clean URL etc.
4) Working with GII Tool:
GII is a GUI tool which can help us to create controller, model, module etc. with help of onscreen guide. We can enable GII from application configuration file, Just need to uncomment GII section under configuration file (application/protected/config/main.php). Need to provide a static password for security, when we can access GII interface then system will ask for GII password. We can do IP address restriction for GII panel.
We can access GII panel with following URL, http://application URL/index.php?r=gii system will ask for password. Need to provide password which we have provided in configuration file.
GII can help us to create various section of an application like, Controller Generator, Crud Generator, Form Generator, Model Generator, Module Generator. Onscreen guide is good enough to work with above sections.
5) Implementation of Theme:
GII very strong in theme and skin. We can easily use multiple theme in single application. Just create a directory(Name of the theme) in /application/themes. as example we can consider our theme name is ‘yiitheme’. We can keep all our design element as well views in ‘yiitheme’ directory. Create ‘views’, ‘css’, ‘images’ directory under ‘yiitheme’ directory and keep files as per directory name. Put ‘theme’=>’yiitheme’ in config file. Si system can call theme instead of core views. Use Yii::app()->theme to call theme elements as example if we want to call style.css file under yiitheme/css/ directory we can put theme->baseUrl ?>/css/style.css in view file where we want it.