Code: Select all
class TableGateway {
protected $table;
protected $columns;
protected $orderby = '';
protected $errorMsg = '';
public function __construct($table, $columns='*') {
$this->table = $table;
$this->columns= $columns;
}
public function orderBy($orderby) {
$this->orderby = " ORDER BY $orderby";
}
public function findAll() {
$result=mysql_query("SELECT {$this->columns} FROM {$this->table}{$this->orderby}") or die (mysql_error());
$thumbnails = array();
if(mysql_num_rows($result) < 1){
$this->errorMsg="There was no content found.";
}else{
while($row=mysql_fetch_array($result)){
$thumbnails[] = $row;
}
return $thumbnails;
}
}
$work= new TableGateway('work', 'id, title, image');
$work->orderBy('id ASC');
$rows = $work->findAll();Code: Select all
class WorkModel extends TableGateway {
public function __construct() {
parent::__construct('work', 'id, title, image');
$this->orderBy('id ASC');
}
}
// and you are back to
$work= new WorkModel();
$rows = $work->findAll();