Skip to content

Instantly share code, notes, and snippets.

@okaprinarjaya
okaprinarjaya / View.php
Created July 8, 2012 09:53
Core Class - View
<?php
class View {
private $templateExtension = '.tpl.php';
private $contentType;
private $controllerName;
public function __construct($controllerName = '', $contentType = '') {
$this->controllerName = $controllerName;
$this->contentType = $contentType;
}
@okaprinarjaya
okaprinarjaya / Controller.php
Created July 8, 2012 14:36
Core Class - Controller
<?php
class Controller {
public function renderTemplate($templateName, $data = null, $contentType = 'html') {
try {
$viewObject = new View(get_called_class(), $contentType);
$viewObject->render($templateName, $data);
} catch(Exception $e) {
echo $e->getMessage();
<?php
class Model {
private $DBConnection = null;
private $DBHandler = null;
public function getConnection() {
try {
$this->DBConnection = new DBConnection(DBConfig::connInfo());
$this->DBHandler = $this->DBConnection->connect();
<?php
class DBConnection {
private $connection = null;
private $DBDriver = '';
private $DBHost = '';
private $DBUser = '';
private $DBPassword = '';
private $DBName = '';
public function __construct($connInfo = array()) {
<?php
class DBConfig {
public static function connInfo() {
$database = array(
'dbdriver' => 'mysql',
'dbhost' => 'localhost',
'dbusername' => 'root',
'dbpassword' => '',
'dbname' => 'webdev'
);
<?php
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
define('APP_PATH', 'C:'.DS.'xampp'.DS.'htdocs'.DS.'testdrive');
define('HOSTNAME', 'http://localhost/testdrive');
define('LIBS_PATH', APP_PATH.DS.'Libs');
define('ASSETS_PATH', HOSTNAME.'/Assets');
define('VENDORS_PATH', APP_PATH.DS.'Vendors');
<?php
class Product extends Model {
public function createProduct() {
}
}
<?php
class ProductController extends Controller {
public function index() {
$this->renderTemplate('index');
}
public function sebuahMethodAction() {
$this->renderTemplate('sebuah_method_action');
}
<?php
include('Bootstrap.php');
require_once(APP_PATH.DS.'Controllers'.DS.'ProductController.php');
$product = new ProductController();
$action = $product->getAction();
switch ($action) {
case 'index':
$product->index();
<h2 style="color:brown;">Walalalalalala</h2>
<p>
Ini adalah output template method sebuahMethodAction() xixixixixixi
kamu suka kan? harus suka donk!
</p>