账户中心 我的话题 我的评论 退出系统

调用其他控制器

调用其他控制器

在控制器内直接使用 new 关键字实例化其他控制器类即可完成对其他控制器的调用

演示代码

在 index 控制器内调用 test 控制器并执行其 runme 方法 :

test.php 源码

<?php
class testController extends grace{
	public function runme(){
		echo 'run...';
	}	
}

index.php 源码

class indexController extends grace{
	public function index(){
		//系统会自动调用视图 index_index.php
		$testController = new testController();
		// 设置 gets 数据
		$testController->gets = array(1,2,3,'test...');
		$testController->runme();
	}
	
}