This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* DJBX33A (Daniel J. Bernstein, Times 33 with Addition) | |
* | |
* This is Daniel J. Bernstein's popular `times 33' hash function as | |
* posted by him years ago on comp.lang.c. It basically uses a function | |
* like ``hash(i) = hash(i-1) * 33 + str[i]''. This is one of the best | |
* known hash functions for strings. Because it is both computed very | |
* fast and distributes very well. | |
* | |
* The magic of number 33, i.e. why it works better than many other |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Model\Table\Behavior; | |
trait UpdateCounterCacheTrait { | |
public function cleanupBelongsToMany($return_count = null) { | |
if($return_count) { | |
return $count; | |
} | |
return $this; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* use like: | |
* httpPostDataFile( | |
* 'https://www.google.com/search', // the url to post to, optionally including get parameters like: ?this=that&here=there | |
* [ | |
* 'q' => 'php http upload file', // post data like: <input name="q" value="php http upload file" /> | |
* ... | |
* ], [ | |
* 'image' => [ // the input name used like: <input name="image" type="file" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Listener; | |
use Cake\Utility\Inflector; | |
use Crud\Listener\BaseListener; | |
use Crud\Event\Subject; | |
class ContainedModelsListener extends BaseListener { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$registry = $this->helpers(); | |
$helpers = $this->helpers; | |
pr($helpers); | |
/* | |
Array( | |
[CrudView] => Array( | |
[className] => App\View\Helper\CrudViewHelper | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ParticipantsTable extends AppTable | |
{ | |
public function beforeMarshal(Event $event, \ArrayObject $data, \ArrayObject $options) { | |
if(isset($data['partner']) && is_array($data['partner'])) { | |
$participant = $this->get($data['id']); | |
$data['partner']['participant_type_id'] = $participant->type_id; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ATable extends \Cake\ORM\Table | |
{ | |
public function validationDefault(Validator $validator) | |
{ | |
$fields = ['salutation', 'firstname', 'lastname']; | |
$validator | |
->provider('allEmptyOrFilled', $fields); | |
foreach($fields as $field) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controller; | |
class AppController extends \Cake\Controller\Controller | |
{ | |
public function initialize() | |
{ | |
parent::initialize(); | |
/* | |
* Can't listen on the "initialize" event here obviously, "startup" and all later ones do work though. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controller; | |
class AController extends AppController { | |
public function index() { | |
try { | |
$this->set('data', $this->paginate()); | |
} catch(\Cake\Network\Exception\NotFoundException $e) { | |
$this->redirect(['page' => 1] + $this->request->query); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AModel { | |
var $hasMany = array( | |
'Field' => array( | |
'className' => 'Field', | |
'foreignKey' => '', | |
'dependent' => false, | |
'conditions' => '', | |
'fields' => '', |
NewerOlder