Skip to content

Instantly share code, notes, and snippets.

@dragoonis
Created September 30, 2011 17:04
Show Gist options
  • Save dragoonis/1254361 to your computer and use it in GitHub Desktop.
Save dragoonis/1254361 to your computer and use it in GitHub Desktop.
<?php
class APP_Controller_Test extends APP_Controller_Application {
function index() {
$model = new APP_Model_Test();
$rows = $model->getAllRows();
$data = array('foo' => 'bar', 'user' => 'ppi_user');
$newID = $model->addRow($data);
$this->redirect('user/profile/' . $newID);
}
}
<?php
// Extends nothing
class App_Model_Test {
protected $_name = 'users'; // Table name
protected $_primary = 'id'; // Table Key
protected $_handler = null;
function __construct() {
$ds = new PPI_DataSource();
$this->_handler = $ds->factory('mysql'); // Name defined in the index.php
}
function getAllRows() {
return $this->_handler->query('select count(*) count from product_views')->fetchAll();
}
function addRow(array $data) {
$this->_handler->insert($this->_name, $data);
return $this->_handler->lastInsertId();
}
}
<?php
require '../ppi/init.php';
// Create a DS reference as 'mysql'
PPI_DataSource::add('mysql', array(
'type' => 'pdo_mysql',
'host' => 'localhost',
'dbname' => 'mydb',
'user' => 'root',
'pass' => 'p4ssw0rd'
));
$app = new PPI_App();
$app->siteMode = 'development';
$app->configBlock = 'development';
$app->boot();
$app->dispatch();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment