abstract class Model{
protected $table;
protected $key;
function findAll(){
return $this->fetch("SELECT * FROM `{$this->table}`");
}
function findById($id){
return $this->fetch("SELECT * FROM `{$this->table}` WHERE {$this->key} = {$id}");
}
protected function fetch($query)
{
$stmt = Connection::con()->query($query);
$stmt->setFetchMode(\PDO::FETCH_ASSOC);
$data = $stmt->fetch();
return $data;
}
}
class News extends Model {
protected $table = 'news';
protected $key = 'id';
public function allNews() {
if(!$rows = $this->findAll()){
throw new \Exception('not find news');
}
return $rows;
}
}
$filename='invoice.xlsx';
header('Content-Type: application/vnd.openxmlformats-officedocument.excelprocessingml.document');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0'); //no cache
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
die();
function test(){
$container = &container_instance();//singliton
$config = $container->get('config');
}
namespace Acme\ServiceProvider;
use League\Container\ServiceProvider\AbstractServiceProvider;
class ConfigProvider extends AbstractServiceProvider
{
protected $provides = [
'config'
];
public function register()
{
$this->getContainer()->add('config', function(){
return [
'test' => 'test'
];
});
}
}
protected function renderPage($page,$data = []) {
$html = $this->load->view("document_top",[],true);
$html .=$this->load->view("document_head",[],true);
$html .= $this->load->view($page,$data,true);
$html .= $this->load->view("document_bottom",[],true);
$this->output->set_output( $html );
}
class User extends MY_Controller {
public function Index(){
$userlist = [];
// logic
$this->renderPage('users',[
'userlist' => $userlist
]);
}
}