Last active
December 17, 2015 09:48
-
-
Save williamn/5589821 to your computer and use it in GitHub Desktop.
Code samples for https://github.com/ptwgs/elnusa-framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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