The following method acts as a route. how does it complete this process?
/*** Controller scheduling **/private static function control () {// second-level domain name // var_dump ($ GLOBALS ['setting _ config'] ['enabled _ subdomain ']); if ($ GLOBALS ['setting _ config'] ['enabled_subdomain '] = '1' & $ _ GET ['AC'] = 'index '&& $ _ GET ['OP'] = 'index ') {$ store_id = subdomain (); if ($ store_id> 0) $ _ GET ['act '] = 'show _ store';} $ act_file = realpath (BASE_PATH. '/control /'. $ _ GET ['act ']. '. php '); $ class_name = $ _ GET ['AC']. 'control '; // Echo $ act_file; if (! @ Include ($ act_file) {if (C ('debug') {throw_exception ("Base Error: access file isn' t exists! ");} Else {showMessage ('Sorry! The page you accessed does not exist ', '', 'html', 'error');} if (class_exists ($ class_name) {$ main = new $ class_name (); $ function = $ _ GET ['OP']. 'OP'; if (method_exists ($ main, $ function) {$ main-> $ function ();} elseif (method_exists ($ main, 'indexop ')) {$ main-> indexOp ();} else {$ error = "Base Error: function $ function not in $ class_name! "; Throw_exception ($ error) ;}} else {$ error =" Base Error: class $ class_name isn' t exists! "; Throw_exception ($ error );}}
Reply to discussion (solution)
Determine the class and method to be called based on controler and action
$act_file = realpath(BASE_PATH.'/control/'.$_GET['act'].'.php');$class_name = $_GET['act'].'Control';
Then, you can determine whether the class and method are called if they exist.
if (class_exists($class_name)){ $main = new $class_name(); $function = $_GET['op'].'Op'; if (method_exists($main,$function)){ $main->$function(); }elseif (method_exists($main,'indexOp')){ $main->indexOp(); }else { $error = "Base Error: function $function not in $class_name!"; throw_exception($error); } }