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

}

}

原文地址:https://www.cnblogs.com/zhengyanbin2016/p/5390071.html