I'm pretty new to the MVC concept itself but I'm slowly starting to grasp it, and what it is that makes it so useful.
I have in my app different tabs which are levels in a hierarchy (I call them entities), each represented by two classes - a Binding class with all the methods to communicate with the database and a helper class which is just a skeleton of the Entity, both in same file. I wonder if this is the right way to approach the design pattern? I haven't built a Model or a Controller yet because I'm not sure where they'll come in at the moment. Also I'm not interested to use ORM right now.
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
[...]
}
Do I need a model class now? I was considering the Controller could perform the ->get function and load appropriate class, because the name of the entity is passed from the front-end with AJAX.
By the way I also am really confused. Should the controller absorb all AJAX requests or should I make a file called ajax.php that handles that, and put the Controller class above public_html so users can't access the class file?