Skip to content

Instantly share code, notes, and snippets.

@UndergroundLabs
Created July 23, 2015 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UndergroundLabs/702d1ad9a29ec33b347f to your computer and use it in GitHub Desktop.
Save UndergroundLabs/702d1ad9a29ec33b347f to your computer and use it in GitHub Desktop.
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