- Gii – Generating Module
- Gii – Generating Controller
- Gii – Creating a Model
- Yii - Gii
- Yii - Localization
- Yii - Authorization
- Yii - Authentication
- Yii - Error Handling
- Yii - Logging
- Yii - Aliases
- Yii - Fragment Caching
- Yii - Caching
- Yii - Testing
- Yii - Fields
- Yii - RESTful APIs in Action
- Yii - RESTful APIs
- Yii - Theming
- Yii - Database Migration
- Yii - Active Record
- Yii - Query Builder
- Yii - Data Access Objects
- Yii - Database Access
- Yii - Dependency Injection
- Yii - Configurations
- Yii - Creating a Behavior
- Yii - Behaviors
- Yii - Creating Event
- Yii - Events
- Yii - GridView Widget
- Yii - ListView Widget
- Yii - Data Widgets
- Yii - Data Providers
- Yii - Properties
- Yii - Sorting
- Yii - Pagination
- Yii - Formatting
- Yii - Files Upload
- Yii - Using Cookies
- Yii - Cookies
- Yii - Using Flash Data
- Yii - Sessions
- Yii - AJAX Validation
- Yii - Ad Hoc Validation
- Yii - Validation
- Yii - HTML Forms
- Yii - Rules of URL
- Yii - URL Routing
- Yii - URL Formats
- Yii - Responses
- Yii - HTTP Requests
- Yii - Creating Extensions
- Yii - Extensions
- Yii - Asset Conversion
- Yii - Assets
- Yii - Layouts
- Yii - Views
- Yii - Modules
- Yii - Widgets
- Yii - Models
- Yii - Using Actions
- Yii - Using Controllers
- Yii - Controllers
- Yii - Entry Scripts
- Yii - Application Structure
- Yii - Create Page
- Yii - Installation
- Yii - Overview
- Yii - Home
Yii Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Yii - Entry Scripts
Entry scripts are responsible for starting a request handpng cycle. They are just PHP scripts accessible by users.
The following illustration shows the structure of an apppcation −
Web apppcation (as well as console apppcation) has a single entry script. The End user makes request to the entry script. Then the entry script instantiates apppcation instances and forwards requests to them.
Entry script for a console apppcation is usually stored in a project base path and named as yii.php. Entry script for a web apppcation must be stored under a web accessible directory. It is often called index.php.
The Entry scripts do the following −
Define constants.
Register Composer autoloader.
Include Yii files.
Load configuration.
Create and configure an apppcation instance.
Process the incoming request.
The following is the entry script for the basic apppcation template −
<?php //defining global constants defined( YII_DEBUG ) or define( YII_DEBUG , true); defined( YII_ENV ) or define( YII_ENV , dev ); //register composer autoloader require(__DIR__ . /../vendor/autoload.php ); //include yii files require(__DIR__ . /../vendor/yiisoft/yii2/Yii.php ); //load apppcation config $config = require(__DIR__ . /../config/web.php ); //create, config, and process reques (new yiiwebApppcation($config))->run(); ?>
The following is the entry script for the console apppcation −
#!/usr/bin/env php <?php /** * Yii console bootstrap file. * @pnk http://www.yiiframework.com/ * @copyright Copyright (c) 2008 Yii Software LLC * @pcense http://www.yiiframework.com/pcense/ */ //defining global constants defined( YII_DEBUG ) or define( YII_DEBUG , true); //register composer autoloader require(__DIR__ . /vendor/autoload.php ); require(__DIR__ . /vendor/yiisoft/yii2/Yii.php ); //load config $config = require(__DIR__ . /config/console.php ); //apply config the apppcation instance $apppcation = new yiiconsoleApppcation($config); //process request $exitCode = $apppcation->run(); exit($exitCode); ?>
The best place for defining global constants is entry scripts. There are three supported by Yii constants −
YII_DEBUG − Defines whether you are in debug mode or not. If set to true, then we will see more log data and detail error call stack.
YII_ENV − Defines the environment mode. The default value is prod. Available values are prod, dev, and test. They are used in configuration files to define, for example, a different DB connection (local and remote) or other values.
YII_ENABLE_ERROR_HANDLER − Specifies whether to enable the default Yii error handler.
To define a global constant the following code is used −
//defining global constants defined( YII_DEBUG ) or define( YII_DEBUG , true); which is equivalent to: if(!defined( YII_DEBUG )) { define( YII_DEBUG , true); }
Note − The global constants should be defined at the beginning of an entry script in order to take effect when other PHP files are included.
Advertisements