Skip to content

Instantly share code, notes, and snippets.

@williamn
Last active December 17, 2015 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save williamn/5589821 to your computer and use it in GitHub Desktop.
Save williamn/5589821 to your computer and use it in GitHub Desktop.
<?php
// The Slim Framework helps you map resource URIs to callback functions
// for specific HTTP request methods (e.g. GET, POST, PUT, DELETE, OPTIONS or HEAD).
// A Slim application will invoke the first route that matches
// the current HTTP request’s URI and method.
// If the Slim application does not find routes with URIs that match
// the HTTP request URI and method, it will automatically
// return a 404 Not Found response.
// For more information, head to
// http://docs.slimframework.com/#Routing-Overview
$app->get('/', function () { Controllers\Todos::getTodos(); });
<?php
namespace Models;
use Zend\Db\Sql\Sql;
use Zend\Db\ResultSet\ResultSet;
Class Todo
{
public function getAll()
{
$database = new \Models\Database;
$sql = new Sql($database->adapter);
$select = $sql->select();
$select->from('TODOS');
$statement = $sql->prepareStatementForSqlObject($select);
$result = $statement->execute();
$resultSet = new ResultSet;
$resultSet->initialize($result);
$todoList = array();
foreach ($resultSet as $row) {
$todoList[] = array(
'id' => $row->ID,
'name' => $row->NAME,
'description' => $row->DESCRIPTION
);
}
return $todoList;
}
}
<?php
namespace Controllers;
Class Todos
{
public static function getTodos()
{
$model = new \Models\Todo;
$todos = $model->getAll();
$todoList = array('todos' => $todos);
echo json_encode($todoList);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment