zoukankan      html  css  js  c++  java
  • [Yii Framework] Embed a view file of the class which implement the CAction.

    In Yii, we can define an action class and ask the controller to instantiate it. And we always create ourselves actions class in rootPath/protected/extensions, and the view file we called in the actions class always are located in rootPath/protected/views/ControllerNAME or rootPath/themes/ThemeNAME/ControllerNAME, then when we use the same actions class in different controllers, we have to copy it from one controller to the other controller, so we also need the "same" view file work for us, here is an example.
    Here is the structure of the files.
    | | |~extensions/
    | | | `~actions/
    | | |   |~views/
    | | |   | `-MyTestAction.php*
    | | |   `-MyTestAction.php*
    The view file MyTestAction.php is located in rootPath/protected/extensions/actions/views, The MyTestAction.php is located in rootPath/protected/extensions/actions

      

    The view file: 

    Hello, world! The view file is under ext.actions.views!

    The actions files 

    代码
    class MyTestAction extends CAction
    {
        
    public function run()
        {
            
    //The other code.
            $this->getController()->render('ext.actions.views.MyTestAction');//Please be aware of the string, it points to the path of the view file!
        }
    }
    Please see the details of how to create and use the actions.
    Ok, that is all.

    Have fun with Yii!

  • 相关阅读:
    ES6_函数方法
    Node_初步了解(3)回调,作用域,上下文
    ES6_入门(4)_数组的解构赋值
    ES6_入门(3)_顶层对象属性
    ES6_入门(2)_const命令
    ES6_入门(1)_let命令
    Node_初步了解(2)
    Node_初步了解(1)
    树的基本知识
    JS_高程5.引用类型(6)Array类型的位置方法,迭代方法,归并方法
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/1932173.html
Copyright © 2011-2022 走看看