![Yii Tutorial](/yii/images/yii-mini-logo.jpg)
- Yii Tutorial
- Yii - Home
- Yii - Overview
- Yii - Installation
- Yii - Create Page
- Yii - Application Structure
- Yii - Entry Scripts
- Yii - Controllers
- Yii - Using Controllers
- Yii - Using Actions
- Yii - Models
- Yii - Widgets
- Yii - Modules
- Yii - Views
- Yii - Layouts
- Yii - Assets
- Yii - Asset Conversion
- Yii - Extensions
- Yii - Creating Extensions
- Yii - HTTP Requests
- Yii - Responses
- Yii - URL Formats
- Yii - URL Routing
- Yii - Rules of URL
- Yii - HTML Forms
- Yii - Validation
- Yii - Ad Hoc Validation
- Yii - AJAX Validation
- Yii - Sessions
- Yii - Using Flash Data
- Yii - Cookies
- Yii - Using Cookies
- Yii - Files Upload
- Yii - Formatting
- Yii - Pagination
- Yii - Sorting
- Yii - Properties
- Yii - Data Providers
- Yii - Data Widgets
- Yii - ListView Widget
- Yii - GridView Widget
- Yii - Events
- Yii - Creating Event
- Yii - Behaviors
- Yii - Creating a Behavior
- Yii - Configurations
- Yii - Dependency Injection
- Yii - Database Access
- Yii - Data Access Objects
- Yii - Query Builder
- Yii - Active Record
- Yii - Database Migration
- Yii - Theming
- Yii - RESTful APIs
- Yii - RESTful APIs in Action
- Yii - Fields
- Yii - Testing
- Yii - Caching
- Yii - Fragment Caching
- Yii - Aliases
- Yii - Logging
- Yii - Error Handling
- Yii - Authentication
- Yii - Authorization
- Yii - Localization
- Yii - Gii
- Gii – Creating a Model
- Gii – Generating Controller
- Gii – Generating Module
- Yii Useful Resources
- Yii - Quick Guide
- Yii - Useful Resources
- Yii - Discussion
Gii - Generating Controller
Let us see how to generate a Controller.
Step 1 − To generate a controller with several actions, open the controller generator interface fill in the form.
![Generate Controller](/yii/images/generate_controller.jpg)
Step 2 − Then, click the “Preview” button and “Generate”. The CustomController.php file with index, hello, and world actions will be generated in the controllers folder.
<?php namespace app\controllers; class CustomController extends \yii\web\Controller { public function actionHello() { return $this->render('hello'); } public function actionIndex() { return $this->render('index'); } public function actionWorld() { return $this->render('world'); } } ?>
Form Generation
Step 1 − To generate a view file from an existing model, open the form generation interface and fill in the form.
![Form Generation](/yii/images/form_generation.jpg)
Then, click the “Preview” button and “Generate”. The customview view file will be generated in the view folder.
Step 2 − To display it, add a new method to the CustomController.
public function actionView() { $model = new MyUser(); return $this->render('/customview', [ 'model' => $model, ]); }
Step 3 − To see the generated view file, open the URL http://localhost:8080/index.php?r=custom/view.
![Generated View File](/yii/images/generated_view_file.jpg)
Advertisements