Skip to content

Instantly share code, notes, and snippets.

@bravo-kernel
bravo-kernel / gist:5568181
Last active December 17, 2015 06:49
CakePHP RestKit Plugin - HAL responses when listing collections

##CakePHP RestKit plugin - HAL responses when listing collections##

More information about the HAL convention can be found at http://stateless.co/hal_specification.html

Examples:

  • Example 1: minimalistic response with resource-links only
  • Example 2: rich response using additional find() fields
  • Example 3: rich response with an _id field pointing to an internal resource (automatic)
  • Example 4: rich response with an _id field pointing to an external resource (manual)
@bravo-kernel
bravo-kernel / gist:5568855
Last active December 17, 2015 06:58
CakePHP RestKit Plugin - HAL responses when viewing entities

##CakePHP RestKit Plugin - HAL responses when viewing entities##

More information about the HAL convention can be found at http://stateless.co/hal_specification.html

Examples:

  • Example 1: basic response
  • Example 2: basic response with an _id field pointing to an internal resource (automatic)
  • Example 3: basic response with an _id field pointing to an external resource (manual)
@bravo-kernel
bravo-kernel / run_shellshocker_at_login.sh
Created October 4, 2014 14:32
Update and run Shellshocker at login
#!/bin/bash
# Update and run Shellshocker at login (by adding script to ~/.bashrc).
# Assumes cloned https://github.com/wreiske/shellshocker repositiory
DIR=/home/vagrant/.shellshocker
SCRIPT=/home/vagrant/.shellshocker/shellshock_test.sh
LOG=$DIR/log
# Update git repository
// Shell function
public function listall()
{
Log::info('Should always log to file using the Monolog logger, should only output to screen with -v');
}
@bravo-kernel
bravo-kernel / gist:b1a53d1f6ca0529d071b
Last active August 29, 2015 14:13
Model less CakePHP3 form using Bootstrap-UI plugin
$form = new SiteFileForm();
echo $this->Form->create($form, [
'url' => ['controller' => 'sitefiles', 'action' => 'ajax_add.json'],
['id' => 'form-submit']
]);
echo $this->Form->input('url', [
'label' => ['class' => 'control-label']
]);
echo $this->Form->input('webroot', [
'label' => ['class' => 'control-label']
@bravo-kernel
bravo-kernel / gist:5d0133bf6c61044f38bc
Last active August 29, 2015 14:13
Re-route DashboardsController routes to /dashboard and disable original/default route to /dashboards
<?php
/**
* CakePHP 3.x Routes configuration (/config/routes.php)
*/
use Cake\Core\Plugin;
use Cake\Routing\Router;
Router::scope('/', function ($routes) {
@bravo-kernel
bravo-kernel / gist:b549156fc1ed157be854
Last active August 29, 2015 14:14
Absolute minimal version of a CRUD controller (using the API Listener)
<?php
namespace App\Controller;
/**
* Leanest possible API Controller using friendsofcake/CRUD plugin
*/
class UsersController extends AppController
{
}
@bravo-kernel
bravo-kernel / gist:189cc3f340013f8c27be
Created February 2, 2015 19:30
mapResources() for ApiListener
/**
* Automatically create REST resource routes for all controllers found in your main
* application or in a specific plugin to provide access to your resources
* using /controller/id.json instead of the default /controller/view/id.json.
*
* If called with no arguments, all controllers in the main application will be mapped.
* If called with a valid plugin name all controllers in that plugin will be mapped.
* If combined both controllers from the application and the plugin(s) will be mapped.
*
* This function needs to be called from your application's app/Config/routes.php:
@bravo-kernel
bravo-kernel / gist:926f81e1705d78e9c3ca
Created February 3, 2015 13:29
Custom REST routes for api-prefixed route (does not respect Accept Header)
/**
* Prefixed API routes (served using Crud.ApiListener).
*/
Router::prefix('api', function ($routes) {
// Enable .json extension parsing
$routes->extensions(['json', 'xml']);
/**
* API index route.
@bravo-kernel
bravo-kernel / gist:4ace454107afaf7279a1
Created February 3, 2015 13:30
mapResources for all Controller files found in a prefix route
/**
* Prefixed API routes (served using Crud.ApiListener).
*/
Router::prefix('api', function ($routes) {
// Enable .json extension parsing
$routes->extensions(['json', 'xml']);
// mapResources for all Controller files found in /src/Controller/Api
$dir = new Folder(APP . 'Controller' . DS . 'Api');