Created
July 23, 2015 17:26
-
-
Save UndergroundLabs/702d1ad9a29ec33b347f to your computer and use it in GitHub Desktop.
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
Index.php | |
========= | |
// Setup the view | |
$di->set('view', function() use ($config){ | |
// Create an events manager | |
$eventsManager = new EventsManager(); | |
$eventsManager->attach('view:afterRender', new BanWordsPlugin()); | |
$view = new View(); | |
$view->setViewsDir($config->phalcon->viewsDir); | |
$view->setVars(array( | |
'title' => $config->site->title | |
)); | |
$view->setEventsManager($eventsManager); | |
return $view; | |
}, true); | |
Controller | |
========== | |
/* | |
* Selects a single track based on it's slug value | |
*/ | |
public function singleAction() | |
{ | |
$slug = $this->dispatcher->getParam('slug'); | |
$ip = $this->request->getClientAddress(); | |
$timestamp = time(); | |
/* | |
* Fetch the track from the database | |
*/ | |
$track = Tracks::findFirstBySlug($slug); | |
/* | |
* Check if track exists, redirect to 404 if not | |
*/ | |
/* | |
* Encrypt the slug, IP address and timestamp | |
*/ | |
$crypt = new Crypt(); | |
$downloadHash = $crypt->encryptBase64( | |
sprintf("%s|%s|%s", $track->id, $ip, $timestamp), | |
$this->config->security->key); | |
/* | |
* Set the view paramaters | |
*/ | |
$this->view->downloadHash = $downloadHash; | |
} | |
Routes | |
====== | |
$router->add( | |
'/track/([0-9a-zA-Z-]+)', | |
array( | |
'controller' => 'track', | |
'action' => 'single', | |
'slug' => 1 | |
) | |
); | |
View | |
==== | |
/app/views/track/single.phtml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment