- 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 - Rules of URL
A URL rule is an instance if yiiwebUrlRule. The urlManager components uses the URL rules declared in its rules property when the pretty URL format is enabled.
To parse a request, the URL manager obtains the rules in the order they are declared and looks for the first rule.
Step 1 − Modify the urlManager component in the config/web.php file.
urlManager => [ showScriptName => false, enablePrettyUrl => true, rules => [ about => site/about , ] ],
Step 2 − Go to your web browser at http://localhost:8080/about, you will see the about page.
A URL rule can be associated with query parameters in this pattern −
<ParamName:RegExp>, where −
ParamName − The parameter name
RegExp − An optional regular expression used to match parameter values
Suppose, we have declared the following URL rules −
[ articles/<year:d{4}>/<category> => article/index , articles => article/index , article/<id:d+> => article/view , ]
When the rules are used for parsing −
/index.php/articles is parsed into the article/index
/index.php/articles/2014/php is parsed into the article/index
/index.php/article/100 is parsed into the article/view
/index.php/articles/php is parsed into articles/php
When the rules are used for creating URLs −
Url::to([ article/index ]) creates /index.php/articles
Url::to([ article/index , year => 2014, category => php ]) creates /index.php/articles/2014/php
Url::to([ article/view , id => 100]) creates /index.php/article/100
Url::to([ article/view , id => 100, source => ad ]) creates /index.php/article/100?source=ad
Url::to([ article/index , category => php ]) creates /index.php/article/index?category=php
To add a suffix to the URL, you should configure the yiiwebUrlManager::$suffix property.
Step 3 − Modify the urlComponent in the config/web.php file.
urlManager => [ showScriptName => false, enablePrettyUrl => true, enableStrictParsing => true, suffix => .html ],
Step 4 − Type the address http://localhost:8080/site/contact.html in the address bar of the web browser and you will see the following on your screen. Notice the html suffix.
Advertisements