Yes It Is Simple!
| CodeIgniter | Yii | |
|---|---|---|
| Global Reference | $CI = &get_instance() | Yii::app() |
| Loading Classes | $CI->load | Yii::import |
| Base URL | site_url() | Yii::app()->baseUrl |
| URL creation | site_url($path) | Yii::app()->createUrl($route, $params) |
| Routes | routes.php | main.php => urlManager |
| Naming | Underscore and Capitalization for classes | camelCase everywhere other than DB |
| Helper functions | Present | No predefined folder, but it can be added |
| Class Prefix | CI_ | C |
| Base Controller | CI_Controller | CController |
| Intermediate Controller | MY_Controller extends CI_Controller | Controller extends CController |
| Approach | Singleton | Pure OO with ORM |
| Folder separator | / (Forward Slash) | . (Dot, like Java) |
| Path Aliases | - Absent - | Yii::setPathOfAlias(‘bootstrap’, dirname(__FILE__).’/../extensions/bootstrap’); |
| Configuration files | /application/config/config.php, constants.php, database.php, routes.php | main.php |
| Autoload | autoload.php | main.phparray(‘import’=>[‘ ‘]) |
| Rendering sequence | header => body => footer | body => layout |
| Third party API folder | /application/libraries | /application/vendors |
| Javascript and CSS | Custom | Built in using Yii::app()->registerCSS, registerJS, clientScript etc |
Concepts new in Yii
- Modules – Bigger Parts of website like Admin Panel and User Area. They use the same database but they represent two different aspects. Example: Gii
- Components are programming parts like (configured from main.php)
- User management
- db
- urlManager
- log
- Widgets are components for meant for presentation, like
- GridView
- ActiveForm
- http://www.yiiframework.com/wiki/146/how-to-use-a-widget-as-an-action-provider
- Layouts provide layout to the page, the main content of the view is written in respective view files and then they are passed to layouts for the final rendering.
- Third Party APIs integration
http://www.yiiframework.com/doc/guide/1.1/en/extension.integration - Protected folder This folder holds the PHP files and there is no direct access from browser to this folder. Files needed by the browser from this folder are exported during runtime in external assets folder
- Where to write JavaScript?
http://www.yiiframework.com/wiki/394/javascript-and-ajax-with-yii/ - How to include JS and CSS?
http://stackoverflow.com/questions/1998449/include-css-javascript-file-in-yii-framework - Themes Folder /themes It can be set in main.php => theme
Theme specific URL is Yii::app()->theme->baseUrl; - AJAX? is incorporated in the same controller which can be kept in a different folder for a better modularity. We write conditional codes for AJAX using
- Yii::app()->request->isAjaxRequest
