我的PHP代码:
class FrontEndController extends BaseController {
public function Welcome()
{
return View::make('frontend.index');
}
public function Modules($param="")
{
/* convert parameter "$param" be a function */
$prefix = "Mod_"; // func prefix's
if (function_exists($this->$prefix.$param)) {
return $this->$prefix.$param();
}else
{
return $param;
}
}
protected function Mod_product(){
return "You are called CATEGORY";
}
protected function Mod_promo(){
return "You are called PROMO";
}
}
当我使用FrontEndController->Modules('product');
它时,我希望它从Mod_product()返回值,所以当我使用FrontEndController->Modules('promo');
它时,它也会从Mod_promo()返回值。这该怎么做?
$prefix = "Mod_"; // func prefix's
$function = $prefix.$param;
if ( method_exists( $this, $function ) ) {
return $this->$function();
} else {
return $param;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句