控制器
- ControllerID/ActionID
- ModuleID/ControllerID/ActionID(属于模块下的控制器)
控制器 ID 应仅包含英文小写字母, 数字, 下划线, 中横杠和正斜杠
article 对应 App\controllers\ArticleController;
post-comment 对应 App\controllers\PostCommentController;
admin/post-comment 对应 App\controllers\admin\PostCommentController;
adminPanels/post-comment 对应 App\controllers\adminPanels\PostCommentController
方法(操作)
index 和 hello-world
public function actionIndex() public function actionHelloWorld()
操作 ID 应仅包含英文小写字母, 数字, 下划线和中横杠, 操作 ID 中的中横杠用来分隔单词.
独立操作
- public function actions() {
- return [ // 用类来申明 "error" 操作'error' => 'yii\web\ErrorAction', // 用配置数组申明 "view" 操作'view' => [ 'class' => 'yii\web\ViewAction', 'viewPrefix' => '', ], ]; }
- // 用户浏览器跳转到 http://example.com return $this->redirect('http://example.com');
默认操作, 默认 index, 可以自定义
public $defaultAction = 'home'; public function actionHome() { return $this->render('home'); }
控制器的生命周期
- beforeAction()
- afterAction()
来源: http://www.bubuko.com/infodetail-3167528.html