简体   繁体   English

如何从yii中的控制器获得所有动作?

[英]How can i get all action from controller in yii?

I have controller : RolePermissionController.php I wants get all action from this controller, here is my controller. 我有控制器:RolePermissionController.php,我想从该控制器获取所有操作,这是我的控制器。 How can i get this ? 我怎么能得到这个? Any help will be really appreciated. 任何帮助将不胜感激。

<?php

class RolepermissionController extends GxController {


    public function actionView($id) {
        $this->render('view', array(
            'model' => $this->loadModel($id, 'Rolepermission'),
        ));
    }

    public function actionCreate() {
        $model = new Rolepermission;


        if (isset($_POST['Rolepermission'])) {
            $model->setAttributes($_POST['Rolepermission']);

            if ($model->save()) {
                if (Yii::app()->getRequest()->getIsAjaxRequest())
                    Yii::app()->end();
                else
                    $this->redirect(array('view', 'id' => $model->RoleID));
            }
        }
                $appControllerPath = Yii::getPathOfAlias('application.controllers'); 
                if(is_dir($appControllerPath))
                    $fileLists = CFileHelper::findFiles($appControllerPath);
                foreach($fileLists as $controllerPath)
                { 
                    $controllerName = substr($controllerPath,  strrpos($controllerPath, DIRECTORY_SEPARATOR)+1,-4);   
                }
        $this->render('create', array( 'model' => $model));
    }

    public function actionUpdate($id) {
        $model = $this->loadModel($id, 'Rolepermission');


        if (isset($_POST['Rolepermission'])) {
            $model->setAttributes($_POST['Rolepermission']);

            if ($model->save()) {
                $this->redirect(array('view', 'id' => $model->RoleID));
            }
        }

        $this->render('update', array(
                'model' => $model,
                ));
    }

    public function actionDelete($id) {
        if (Yii::app()->getRequest()->getIsPostRequest()) {
            $this->loadModel($id, 'Rolepermission')->delete();

            if (!Yii::app()->getRequest()->getIsAjaxRequest())
                $this->redirect(array('admin'));
        } else
            throw new CHttpException(400, Yii::t('app', 'Your request is invalid.'));
    }

    public function actionIndex() {
        $dataProvider = new CActiveDataProvider('Rolepermission');
        $this->render('index', array(
            'dataProvider' => $dataProvider,
        ));
    }

    public function actionAdmin() {
        $model = new Rolepermission('search');
        $model->unsetAttributes();

        if (isset($_GET['Rolepermission']))
            $model->setAttributes($_GET['Rolepermission']);

        $this->render('admin', array(
            'model' => $model,
        ));
    }

}

Use this extension to get actions of controller, 使用此扩展程序可以获取控制器的操作,

Reference Here: http://www.yiiframework.com/extension/metadata/ 此处参考: http : //www.yiiframework.com/extension/metadata/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM