Created
April 10, 2015 12:42
-
-
Save tobsn/12b7181977eb292ddbd7 to your computer and use it in GitHub Desktop.
slim smarty gump yamop (mongodb)
This file contains 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
RewriteEngine On | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteRule ^ index.php [QSA,L] |
This file contains 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 | |
require( 'vendor/autoload.php' ); | |
$app = new \Slim\Slim(['view'=>new \Slim\Views\Smarty()]); | |
$view = $app->view(); | |
$view->parserExtensions = ['vendor/slim/views/Slim/Views/SmartyPlugins']; | |
$view->parserDirectory = '../templates'; | |
$view->parserCompileDirectory = '../templates/compiled'; | |
$view->parserCacheDirectory = '../templates/cache'; | |
$view->setTemplatesDirectory( '../templates' ); | |
$view->error_reporting = E_ALL & ~E_NOTICE; | |
$connection = new \MongoClient(); | |
\Mawelous\Yamop\Mapper::setDatabase( $connection->myitems ); | |
$G = new GUMP(); |
This file contains 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
{ | |
"autoload": { | |
"classmap": [ | |
"models" | |
] | |
}, | |
"require": { | |
"slim/slim": "~2.6", | |
"slim/views": "0.1.*", | |
"smarty/smarty": "~3.1", | |
"mawelous/yamop": "0.2.*", | |
"wixel/gump": "dev-master" | |
} | |
} |
This file contains 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
<table> | |
<thead> | |
<tr> | |
<th>Name</th> | |
<th>Last Changed</th> | |
<th></th> | |
</tr> | |
</thead> | |
<tbody> | |
{foreach $data as $d} | |
<tr> | |
<td dl="Name">{$d.name}</td> | |
<td dl="Last Changed"><script>ago({$d.updated_at->sec})</script></td> | |
<td dl=""><a href="/item/delete/{$d._id}" onclick="return confirm('are you sure?');">Delete</a></td> | |
</tr> | |
{/foreach} | |
</tbody> | |
</table> | |
<hr /> | |
<form action="/item/create" method="post"> | |
URL: <input type="text" name="name" /> | |
<input type="submit"> | |
</form> |
This file contains 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 require( 'bootstrap.php' ); | |
$app->get( '/', function() use ($app) { | |
$data = Item::find()->sort( [ '_id' => -1 ] )->getArray(); | |
$app->render( 'index.tpl', [ '__content' => $app->view->fetch( 'dashboard.tpl', [ 'data' => $data ] ) ] ); | |
})->name( 'root' ); | |
$app->get( '/item/delete/:id', function( $id ) use ( $app ) { | |
if( $data = Item::findById( $id ) ) $data->remove(); | |
$app->response->redirect( $app->urlFor( 'root' ), 303 ); | |
}); | |
$app->post( '/item/create', function() use ( $app, $G ) { | |
$data = $G->filter( $G->sanitize( $app->request->post(), ['name'] ), [ 'name' => 'trim|sanitize_string' ] ); | |
if( $G->validate( $data, [ 'name' => 'required|valid_url' ] ) === true ) (new Item( $data ))->save(); | |
$app->response->redirect( $app->urlFor( 'root' ), 303 ); | |
}); | |
$app->run(); |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"> | |
<style type="text/css">{literal} | |
body{font-family:arial} | |
table{border:1px solid #ccc;width:100%;margin:0;padding:0;border-collapse:collapse;border-spacing:0}table tr{border:1px solid #ddd;padding:0}table th,table td{padding:10px;text-align:center}table th{text-transform:uppercase;font-size:14px;letter-spacing:1px}table td:first-child{width:30px}@media screen and (max-width: 600px){table{border:0}table thead{display:none}table tr{margin-bottom:10px;display:block;border-bottom:2px solid #ddd}table td{display:block;text-align:right;font-size:13px;border-bottom:1px dotted #ccc}table td:first-child{width:100%}table td:last-child{text-align:center;border-bottom:0}table td:before{content:attr(dl);float:left;text-transform:uppercase;font-weight:700}} | |
{/literal}</style> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.1/moment.min.js"></script> | |
<script type="text/javascript">{literal} | |
function ago(ts){ | |
document.write(moment.unix(ts).fromNow()) | |
} | |
{/literal}</script> | |
</head> | |
<body> | |
{$__content} | |
</body> | |
</html> |
This file contains 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 | |
class Item extends \Mawelous\Yamop\Model { | |
protected static $_collectionName = 'items'; | |
public static $timestamps = true; | |
} |
This file contains 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
htdocs | |
- models | |
- items.php | |
.htaccess | |
bootstrap.php | |
composer.json | |
index.php | |
templates | |
- compiled | |
- cached | |
index.tpl | |
dashboard.tpl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment