美文网首页
yii初体验(5)控制器 操作的简单介绍

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

作者: 子枫Eric | 来源:发表于2019-08-23 22:11 被阅读0次

    控制器

    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()

    相关文章

      网友评论

          本文标题:yii初体验(5)控制器 操作的简单介绍

          本文链接:https://www.haomeiwen.com/subject/leuxectx.html