• 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_DOM笔记3
    jquery_DOM笔记2
    mac之jdk环境变量配置
    360导致的mysql问题解决
    windows服务器apache配置https教程
    生成自己openssl的证书
    wkhtmltopdf中文乱码
    安装ruby、rails
    extjs中返回数据时id不能重复,否则数据会被合并
    gzip压缩ext-all.js
  • 原文地址:https://www.cnblogs.com/zhengyanbin2016/p/5390071.html
Copyright © 2020-2023  润新知