【发布时间】:2012-10-18 03:03:26
【问题描述】:
我正在尝试构建一个基于 mvc 的小型应用程序。
如何根据查询字符串调用类中的方法?
例如,$_GET 查询字符串被设置为 load_master_form
http://www.domain.com/settings/load_master_form
为了调用设置类中的方法,我正在做:
function __construct(){
$this->{$_GET['method']}();
}
但显然这不起作用 - 只是无法加载这样的方法。那么如何实现呢?
【问题讨论】:
-
你需要创建一个路由机制.. 我猜this 可能会有所帮助
-
你确定你甚至想做这样的事情吗?如何阻止恶意用户做
example.com?method=blow_up_the_universe? -
@Marc B,该类只加载公共数据,如果该方法不存在则进入404页面。
-
你知道Htaccess重写规则吗?还有一个问题,设置是不是文件夹。?
标签: php model-view-controller class methods