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大家好";

    }

    }

  • 相关阅读:
    springbatch入门练习(第一篇)
    rabbitmq安装错误集
    动态代理和反射概念剖析
    RPC使用rabbitmq实现
    spring amqp初步了解
    aips初步设想
    静态工厂方法和实例工厂方法及普通的bean
    HDU4403(暴搜)
    CodeForces 446B
    HDU5505
  • 原文地址:https://www.cnblogs.com/zhengyanbin2016/p/5390071.html
Copyright © 2011-2022 走看看