Yii framework, the development of which began with the aim of improvising PRADO framework, entered the web development field in the fall of 2008. However, its stable release (version 1.1.11) happened recently (July 29, 2012). It’s not been long since web developers started using Yii, but, surprisingly enough, not much detailed information is there over the Web. Provided this, web developers who are new to Yii often get stuck even in the simplest of its tasks. This post is designed to help such developers understand the basics of Yii, a high-performance framework that is a little complex to get started with but is soon believed to overshadow the other major players like Cake PHP, Code Igniter, Zend and more. We’ll be covering the following areas:
1.Yii application structure
2.How to work with GII tool?
Before knowing the basics, are you wondering why should you switch to Yii or for that matter, why should you be even reading something about it? Is it the usability? Is it the performance? Or is it the excitement for something new?
(Have been liking our posts for a while? Subscribe now! We’ll make sure that you never miss an update. And talk to our web development experts now if you need professional help with your Web strategy.)
Actually, it’s all of them. Yii has proved itself to be one of the most user-friendly frameworks of all time – given you understand its basics very well, which is not at all a heavy-duty task, trust us! Its code snippets are easily available, and it is highly bug free and has a sea of new features (like MVC, caching, authentication…) that are mainly aimed to make it secure and incredibly fast. This lazy-loading technique based framework surpasses all others when it comes to performance.
Yii application structure:
Assets, CSS, images, protected, themes – these are the directories you’ll come across in the MVC-based Yii application.
A. A directory that is very pivotal for Yii is protected directory, encompassing `config’, ‘controllers’, ‘models’, ‘views’, ‘extensions’ and ‘components’.
1. Config directory is designed to store information/data related to application configuration.
2. Controllers – all of them – must be stored in ‘controllers’ directory.
3. Similarly, models in ‘model’ directory.
4. In case you don’t want to use a theme for Yii, you have an option to store all view files in ‘views’ directory and to get CSS, JS and images from Yii’s root folder directories – ’CSS`, ‘JS’, ‘images’, for example
1.’Layouts’ directory is made for storing design layouts – inner page layout, home layout and more.
2. Site is a directory that may contain ‘view’. For other controllers, you can see other controller-named directory in this directory only – like ’site’ views.
5.You have ‘extensions’ directory for store extensions.
6.Components directory, similarly, is for store components.
B. ‘Theme’ directory is designed in case you like to use a theme in Yii. While installing a theme with the help of this directory, you have an option to skip core images, core view and core CSS. Moreover, you can also use multiple themes, but in that case you must rename the themes to the names of directories like view, CSS, JS and images, and save them in the ‘theme’ directory.
1. View folder can be used for storing layouts and controllers.
I. Layouts directory is for storing design layouts – like home layout, inner page layout… — for the theme.
II. Controllers can be saved as a parallel folder.
2. CSS directory, which is designed to store CSS files, can be used for views of theme (application/themes/THEME_NAME/views).
3. JS directory, made to store JS files, can also be used for views of theme (application/themes/THEME_NAME/views).
4. Images directory, designed for image files, can also be used for views of theme (application/THEME_NAME/views).
C. Assets directory, used for storing side components, like ‘Tree,’ ’Jquery’, ‘Widget,’ ‘Tab’ etc. is created by Yii.
D. CSS directory stores CSS files while Yii is using core views.
E. By the same token, images directory stores images while Yii is using core views.
Working with GII tool made easy:
GII, an open source GUI tool and must-have guide when it comes to Yii, helps you create model, module, controller and more. You can enable/uncomment GII tool from Yii’s configuration file (application/protected/config/main.php). For security purposes, however, you must provide a static password – your system will ask for that password when you’ll be able to access GII tool. You can access GII tool with this URL – http://application URL/index.php?r=gii.
GII enables us to create the following:
1. Controller Generator
2. Crud Generator
3. Form Generator
4. Model Generator
5. Module Generator
We hope that by now, besides learning what is GII tool and how it works, you must be knowing how to maintain folders in Yii framework and what should be its structure. In case of any confusion or query, please speak your mind in the comment section below – we would be happy to help!