Ok grazie, cmq per evitare di creare due classi che si occupano sempre di film, una cosa del genere sarebbe sbagliata?
Codice PHP:
class Film {
private $id;
private $title;
function __construct($row) {
$film->setId($row['id']);
$film->setTitle = $row['title'];
}
public static function findById($id) {
$result = $db->query("SELECT * FROM films WHERE id=".$id);
$row = $result->fetch_array();
$film = new Film($row);
return $film;
}
public static function findAll() {
$films = array();
$result = $db->query("SELECT * FROM films");
while($row = $result->fetch_array())
{
$film = new Film($row);
$films[] = $film;
}
return $films;
}
public function getId() {
return $this->id;
}
public function getTitle() {
return $this->title;
}
public function setId($id) {
$this->id = $id;
}
public function setTitle($title) {
$this->title = $title;
}
}