Gii - Bộ điều khiển tạo
Hãy để chúng tôi xem cách tạo Bộ điều khiển.
Step 1 - Để tạo bộ điều khiển bằng một số thao tác, hãy mở giao diện bộ tạo bộ điều khiển, điền vào biểu mẫu.
![](https://post.nghiatu.com/assets/tutorial/yii/images/generate_controller.jpg)
Step 2- Sau đó, nhấp vào nút “Xem trước” và “Tạo”. CácCustomController.php tệp có chỉ mục, xin chào và hành động thế giới sẽ được tạo trong thư mục bộ điều khiển.
<?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');
}
}
?>
Tạo biểu mẫu
Step 1 - Để tạo tệp dạng xem từ một mô hình hiện có, hãy mở giao diện tạo biểu mẫu và điền vào biểu mẫu.
![](https://post.nghiatu.com/assets/tutorial/yii/images/form_generation.jpg)
Sau đó, nhấp vào nút “Xem trước” và “Tạo”. Tệp chế độ xem tùy chỉnh sẽ được tạo trong thư mục chế độ xem.
Step 2 - Để hiển thị nó, hãy thêm một phương thức mới vào CustomController.
public function actionView() {
$model = new MyUser();
return $this->render('/customview', [ 'model' => $model,
]);
}
Step 3 - Để xem tệp chế độ xem đã tạo, hãy mở URL http://localhost:8080/index.php?r=custom/view.
![](https://post.nghiatu.com/assets/tutorial/yii/images/generated_view_file.jpg)