Skip to content

Instantly share code, notes, and snippets.

get('story.json').then(function(response) {
  return JSON.parse(response);
}).then(function(response) {
  console.log("Yey JSON!", response);
});

But, Since JSON.parse takes a single argument and returns a transformed value, we can make a shortcut:

@cwbit
cwbit / routes.php
Created July 25, 2015 21:32
Adding /admin to the admin prefix routes
<?php
# turn on admin routing
Router::prefix('admin', function ($routes) {
$routes->connect('/', ['controller'=>'Pages', 'action'=>'dashboard']);
$routes->fallbacks('InflectedRoute');
});
# tell Cake that /admin (which is NOT a prefix, it's a 'page' in the main route set) into our prefix
# /admin/* is a prefix, /admin is a page on the main (non-prefixed) site
Router::connect('/admin', ['prefix'=>'admin']);
@cwbit
cwbit / ItemsTable.php
Created March 10, 2015 12:44
Example of a finder using a finder. `findAvailable` chains in the `findVisible` from the VisibilityBehavior
<?
/**
* Custom finder method to only return items that are considered 'available'
* An item is available if it is 'visible' and it's quantity on hand is greater than 0
* @param Cake\ORM\Query $query
* @param array $options
* @return Cake\ORM\Query
*/
public function findAvailable(Query $query, array $options){
return $query->find('visible')->where(["{$this->_table->alias()}.quantity_on_hand >=" => 1]);
@cwbit
cwbit / blah.php
Last active August 29, 2015 14:16
<?php
public function resetPassword($code = null){
if(empty($code)):
throw new NotFoundException;
endif;
// Recupero l'utente ha cui è associato il codice di autorizzazione
$user = $this->Users
->find()
@cwbit
cwbit / core.php
Last active August 29, 2015 14:01
Example of how to load different DB configurations based on a config setting in CakePHP
<?php
// code ...
#change base on environment (e.g. 'DEV', 'UAT', 'PROD')
Configure::write('activeEnvironment', 'DEV');
// code ...