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

控制器
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()

转载于:https://www.cnblogs.com/wmc1125/p/11402927.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值