Skip to content

Instantly share code, notes, and snippets.

View Kindari's full-sized avatar

William Cahill-Manley Kindari

  • San Diego, California
View GitHub Profile
@Kindari
Kindari / news.php
Created October 10, 2012 22:02
Numeric arguments to controllers pass to index method
<?php
class News_Controller extends Base_Controller
{
public $restful = true;
public function __call($name, $args)
{
$matches = array();
preg_match('/(action|get|put|delete|post)_(\d+)/', $name, $matches);
if ($matches) {
@Kindari
Kindari / gist:3879716
Created October 12, 2012 15:19
Laravel Filter Route based on Role
<?php
Route::get('protected', array('before' => 'auth|role:admin', function() {
return "Only admins can see this";
}));
Route::filter('role', function ($role) {
if ( ! Auth::user()->has_role( $role ) )
{
return Response::error("401"); // not authorized
public static function addview($tid) {
$viewed = Session::get('viewed', array());
if ( in_array($tid, $viewed) )
{
$viewed[] = $tid;
Theme::where_id($tid)->increment('views');
}
Session::put('viewed', $viewed);
}
@Kindari
Kindari / gist:4070375
Created November 14, 2012 05:05
app/start/artisan.php
<?php
/*
|--------------------------------------------------------------------------
| Register The Artisan Commands
|--------------------------------------------------------------------------
|
| Each available Artisan command must be registered with the console so
| that it is available to be called. We'll register every command so
| the console gets access to each of the command object instances.
Foo
@yield('content')
Bar
@Kindari
Kindari / PageController.php
Created November 24, 2012 12:28 — forked from aranw/PageController.php
Caching issue
<?php
class PageController extends Controller {
/**
* Blog Posts
*
* @var array
**/
protected $posts;
def send(self, command, *args, **kwargs):
#data is base64 encoded later
data = kwargs.pop('data', None)
# all commands must have a transaction id
tid = self.transaction_id
parts = [command, '-i %d' % tid]
if args: # extra arguments
@section('content')
Some Content
@endsection
@section('title')
Some Content | @parent
@endsection
<?php // application/models/user.php
class User extends Eloquent
{
public static $hidden = array('password');
public function set_password($value)
{
return $this->attributes['password'] = Hash::make($value);
}
@Kindari
Kindari / routes.php
Created March 18, 2013 15:59
Role based router filtering for Laravel 3
<?php
Route::get('protected', array('before' => 'auth|has_role:admin', function(){
return "sekrit";
}));
Route::filter('has_role', function($role) {
if ( ! Auth::user()->has_role($role) ) {
return 'unauthorized';
}