【发布时间】:2011-07-19 17:05:39
【问题描述】:
我在 PHP 中的 OOP 编程方面没有太多经验,我的搜索没有给出任何结果,而是直接方法的解决方案。我需要的是这个:
// URL Decides which controller method to load
$page = $_GET['page'];
// I want to load the correct controller method here
$this->$page();
// A method
public function home(){}
// Another method
public function about(){}
// e.g. ?page=home would call the home() method
编辑:我已经尝试了几个建议,但我得到的是内存过载错误消息。这是我的完整代码:
<?php
class Controller {
// Defines variables
public $load;
public $model;
public function __construct() {
// Instantiates necessary classes
$this->load = new Load();
$this->model = new Model();
if (isset($_GET['page'])) {
$page = $_GET['page'];
$fc = new FrontController; // This is what crashes apparently, tried with and without ();
}
}
}
【问题讨论】: