yii初体验(5)控制器 操作的简单介绍

控制器
ControllerID/ActionID
ModuleID/ControllerID/ActionID(属于模块下的控制器)
 
控制器ID应仅包含英文小写字母、数字、下划线、中横杠和正斜杠
 
  • article 对应 appcontrollersArticleController;
  • post-comment 对应 appcontrollersPostCommentController;
  • admin/post-comment 对应appcontrollersadminPostCommentController;
  • adminPanels/post-comment 对应appcontrollersadminPanelsPostCommentController
 
 
方法(操作)
index 和 hello-world
public function actionIndex() public function actionHelloWorld()
操作ID应仅包含英文小写字母、数字、下划线和中横杠,操作ID中的中横杠用来分隔单词。
 
独立操作
public function actions() { return [ // 用类来申明"error" 操作 'error' => 'yiiwebErrorAction', // 用配置数组申明 "view" 操作 'view' => [ 'class' => 'yiiwebViewAction', 'viewPrefix' => '', ], ]; }
 
 
 
// 用户浏览器跳转到 http://example.com return $this->redirect('http://example.com');
 
 
默认操作,默认index,可以自定义
public $defaultAction = 'home'; public function actionHome() { return $this->render('home'); }
 
 
控制器的生命周期
 
beforeAction()
 
afterAction()
原文地址:https://www.cnblogs.com/wmc1125/p/11402927.html