zoukankan      html  css  js  c++  java
  • YII中引用自定义类

    如果通过actions方法引用其他自定义类时

    <?php

    class LoginController extends Controller

    {

    public function actionIndex()

    {

    $userModel = new UserMsg();

    $this->render("index",array("userModel"=>$userModel));

    }

    //以访法的形式在当前控制器里访问其他类

    //这里主要用于访问验证码文件

    //该方法的调用方式为:index.php?r=当前控制器/captcha,就可以该问到该actions里设置的CCaptchaAction类

    public function actions()

    {

    return array(

    "captcha"=>array(

    "class"=>"system.web.widgets.captcha.CCaptchaAction"//要访问framework目录下的CCaptchaAction.php。system代表framework目录

    ),

    //也可以调用其他自定义的类 index.php?r=当前控制器/hellohys,就可以访问到当前这个Person类的run方法了

    "hellohys"=>array(

    "class"=>"application.controllers.Person"

    )

    );

    }

    }

    ?>

    路径app/protected/controllers/Person.php,调用方法:index.php?r=当前控制器/hellohys

    class Person extends CAction

    {

    //该方法必须为run方法

    public function run()

    {

    echo "Hello大家好";

    }

    }

  • 相关阅读:
    委托示例一则
    JQuery学习笔记(3)JQuery中的DOM操作
    JQuery学习笔记(2)JQuery选择器
    把.net的web开发补起来,徐图之
    今天把swagger补了一下
    Azure Cosmos DB Core (SQL)
    wcf callback channel问题多多
    gitlab安装
    Kubernetes
    搜索功能实现
  • 原文地址:https://www.cnblogs.com/zhengyanbin2016/p/5390071.html
Copyright © 2011-2022 走看看