我对 MVC 概念本身还很陌生,但我正在慢慢开始掌握它,以及是什么让它如此有用。
我的应用程序中有不同的选项卡,它们是层次结构中的级别(我称它们为实体),每个选项卡都由两个类表示 - 一个 Binding 类,具有与数据库通信的所有方法,一个助手类只是实体的骨架,都在同一个文件中。我想知道这是否是处理设计模式的正确方法?我还没有构建模型或控制器,因为我不确定它们会在哪里出现。另外我现在对使用 ORM 不感兴趣。
class CompanyBinding extends EntityBinding {
    function __construct() {
        parent::__construct();
    }
    public function get($criteria = array()) {
        // method to retrieve an array of DB rows, each represented by the helper class
            [...]
        return $sth->fetchAll(PDO::FETCH_CLASS, 'Company');
    }
    public function get_by_id($id) {
        // method to retrieve an one single object of the helper class
        $sth->setFetchMode(PDO::FETCH_CLASS, 'Company');
        return $sth->fetch();
    }
}
class Company extends Entity {
    public $id;
    public $name;
    public $email;
    public $phone;
    // just properties. some classes have a __construct() function to manipulate some fields after retrieval
    [...]
}
我现在需要一个模型课吗?我在考虑控制器可以执行 ->get 函数并加载适当的类,因为实体的名称是通过 AJAX 从前端传递的。
顺便说一句,我也很困惑。控制器应该吸收所有 AJAX 请求,还是应该创建一个名为 ajax.php 的文件来处理它,并将 Controller 类放在 public_html 之上,这样用户就无法访问类文件?