Monday, December 17, 2007

PHP 动态调用函数


/**
* $Id$
* Author: zhuzhu@perlchina.org (zhuzhu@isoshu.net)
*/
class Manage
{
var $todo = null;

public function route()
{
$action = &$_GET['action'];
switch($action){
case 'login':
$this->todo = '_login';
break;
case 'build_site':
$this->todo = '_build_site';
break;
case 'system';
$this->todo = '_system';
break;
default:
$this->todo = '_index';
break;
}
$myFun = $this->todo; // 动态调用函数
$this->{$myFun}();
}

private function _index()
{
print 'hi';
}
}

?>

No comments:

Post a Comment