Skip to content

Instantly share code, notes, and snippets.

<?php
if (!empty($this->params['path'])) {
$path = $this->params['path'];
$type = array_shift($path);
$types = array('origin', 'incomplete', 'review');
$types = array_diff($types, array($type));
$moveTo = '<h4>' . __('Move to', true) . '</h4>';
$copyTo = '<h4>' . __('Copy to', true) . '</h4>';
$this->Menu->add('actions', $moveTo, false, null, array('escapeTitle' => false));
$this->Menu->add('actions', $copyTo, false, null, array('escapeTitle' => false));
@hiromi2424
hiromi2424 / gist:759536
Created December 30, 2010 06:56
dynamic call static method
class StaticClass {
function hoge() {
echo 'hoge';
}
function piyo() {
echo 'piyo';
}
}
foreach (array('hoge', 'piyo') as $name) {
@hiromi2424
hiromi2424 / webroot_controller.php
Created January 7, 2011 14:20
webroot controller
<?php
class WebrootController extends AppController {
var $uses = null;
var $_ext = '.php';
function show() {
$path = func_get_args();
$path = implode(DS, $path);
if (in_array($path, array('index', 'css', 'test'))) {
@hiromi2424
hiromi2424 / app_fixture_manager.php
Created February 6, 2011 07:32
auto loading fixtures for cakephp 2.x
<?php
require_once CAKE_TESTS_LIB . 'cake_fixture_manager.php';
class AppFixtureManager extends CakeFixtureManager {
public function fixturize(CakeTestCase $test) {
$this->_autoLoadFixtures($test);
@hiromi2424
hiromi2424 / app_controller.php
Created March 4, 2011 19:05
service model example for CakePHP
<?php
class AppController extends Controller {
var $uses = array('Service');
}
@hiromi2424
hiromi2424 / articles_controller.php
Created March 6, 2011 10:42
service model example with transaction for CakePHP
<?php
class ArticlesController extends AppController {
function add() {
if (!empty($this->data)) {
if ($this->Service->transaction()->saveNewArticle($this->data)) {
$this->Session->setFlash(__('Article has been saved.', true));
$this->redirect(array('action' => 'index'));
} else {
<?php
class Service {
function addArticle($data) {
$this->Transaction->begin();
if (!$this->Article->save($this->Article->create($data))) {
$this->Transaction->begin();
return false;
}
$this->Transaction->commit();
@hiromi2424
hiromi2424 / electricity.js
Created March 25, 2011 06:42
one-liner for japan electricity usage api
<script type="text/javascript">(function () { $.ajax({type: "GET", url: "http://tepco-usage-api.appspot.com/latest.json", dataType: "jsonp", success: function (data) { document.write(parseInt(100 * data.usage/data.capacity) + "%"); } }); })(); </script>
@hiromi2424
hiromi2424 / base_service.php
Created April 16, 2011 01:20
simple transaction service
<?php
/*
* ###############
* # W A R N I N G
* ###############
*
* This implementation is thought of madness.
* So DO NOT use this for basic process of service at your applications.
*/
<?php
class TestClosure {
public $hoge = 'hoge';
public $piyo = 'piyo';
public $fuga = 'fuga';
public function delegate($lambda) {
return $lambda($this);