Skip to content

Instantly share code, notes, and snippets.

@jgornick
jgornick / FileCache.php
Created September 18, 2009 21:59 — forked from robzienert/gist:189307
ZF: Cache Configs
<?php
class Default_Controller_Action_Helper_FileCache extends
Zend_Controller_Action_Helper_Abstract
{
protected $_cache;
public function load($file, $id)
{
return $this->getCache($file)->load($id);
}
@jgornick
jgornick / Form.php
Created October 2, 2009 23:43
ZF: Date GreaterThan & LessThan Validators
<?php
// ...
$this->addElementPrefixPath('My_Validate', 'My/Validate/', 'validate');
$this->addElement('text', 'start_time', array(
'label' => 'Start Time (GMT)',
'class' => 'datetime',
'required' => true,
'validators' => array(
@jgornick
jgornick / IndexController.php
Created October 8, 2009 20:24
ZF: FlashMessenger Setup Action Helper
<?php
class CustomersController extends Zend_Controller_Action
{
public function init()
{
$this->_helper->MessengerSetup->enable($this->view);
}
...
}
@jgornick
jgornick / gist:208754
Created October 12, 2009 21:14
PHP: Capture phpinfo() Output
<?php
function pinfo() {
ob_start();
phpinfo();
$data = ob_get_contents();
ob_clean();
return $data;
}
@jgornick
jgornick / gist:214510
Created October 20, 2009 19:00
Apache: Sample Virtual Host
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "/path/to/root"
ServerName abc.localhost
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/path/to/root">
Options Indexes FollowSymLinks
AllowOverride All
@jgornick
jgornick / format-duration.js
Last active September 3, 2015 22:25
PHP: Format Duration
var duration = 3600;
duration = parseInt(Math.abs(duration));
duration =
String('00' + parseInt(duration / 3600)).slice(-2) + ':' +
String('00' + parseInt((duration / 60) % 60)).slice(-2) + ':' +
String('00' + parseInt(duration % 60)).slice(-2);
@jgornick
jgornick / gist:226283
Created November 4, 2009 18:41
JS: Get Now UTC Date
var now = new Date();
var offset = -now.getTimezoneOffset() * 60 * 1000;
var nowUTC = new Date(+now - offset);
@jgornick
jgornick / gist:227333
Created November 5, 2009 20:01
PHP: HTTP Status Code Script
<?php
// Credit: http://gif.phpnet.org/frederic/programs/http_status_codes/
$code = isset($_GET['code']) ? $_GET['code'] : '200';
header('x', true, $code);
?>
@jgornick
jgornick / gist:229536
Created November 8, 2009 23:12
ZF: Navigation Controller Plugin
<?php
class My_Controller_Plugin_Navigation extends Zend_Controller_Plugin_Abstract
{
/**
* Sets the appropriate page to active.
* NOTE: This is not module safe and only works with controllers/actions.
* NOTE: This plugin is designed for top-level navigations.
*
* @param Zend_Controller_Request_Abstract $request
*/
@jgornick
jgornick / gist:238285
Created November 18, 2009 21:35
ZF: ACL & Auth Action Helper
<?php
class Default_Controller_Action_Helper_Acl extends
Zend_Controller_Action_Helper_Abstract
{
protected $_auth;
protected $_acl;
protected $_action;
protected $_controllerName;
protected $_roleFieldName = 'role';
protected $_disabled = false;