English 中文(简体)
Yii Tutorial

Yii Useful Resources

Selected Reading

Gii – Generating Controller
  • 时间:2024-09-17

Gii - Generating Controller


Previous Page Next Page  

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

Step 2 − Then, cpck the “Preview” button and “Generate”. The CustomController.php file with index, hello, and world actions will be generated in the controllers folder.

<?php
   namespace appcontrollers;
   class CustomController extends yiiwebController {
      pubpc function actionHello() {
         return $this->render( hello );
      }
      pubpc function actionIndex() {
         return $this->render( index );
      }
      pubpc 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

Then, cpck 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.

pubpc 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 Advertisements