Skip to content

Instantly share code, notes, and snippets.

@hiromi2424
hiromi2424 / 01_first.php
Created Sep 1, 2011
preferable example for getting data method for model
View 01_first.php
<?php
class Post extends AppModel {
/**
* Usage:
* $nextPost = $this->Post->getNext(1);
*/
public function getNext($id) {
$greater = $this->find('first', array(
View auto_slug_options.php
<?php
$defautlOptions = array(
'model' => null, // Inflector::classify($controller) by default
'display' => ':displayField', // ルートのスラグに適応されるフィールド。モデルのdisplayFieldがデフォルト
'lookup' => ':primaryKey', // コントローラのアクション引数、URLの指定のpass($id)に渡すべきフィールド。モデルのプライマリーキーがデフォルト。
'cacheConfig' => 'default', // 使用するキャッシュのコンフィグ名。falseを指定するとキャッシュしない。
'recursive' => -1, // モデルのクエリでのrecursiveの値
'named' => ':displayField', // スラグのパラメータ名。/post/:title のtitleに当たるもの。
'identity' => ':name', // インスタンスの名前。デフォルトはモデル名。キャッシュの操作に使う
@hiromi2424
hiromi2424 / upgrade.php
Created Jul 4, 2011
quick upgrade plugins or app
View upgrade.php
<?php
// Usage
// php upgrade.php on app dir or plugin root
class App {
public static function __callStatic($method, $params) {
}
@hiromi2424
hiromi2424 / AppController.php
Created Jul 2, 2011
TwitterKit.TwitterOauthAuthenticate design
View AppController.php
<?php
class AppController extends Controller {
public $components = array(
'Auth' => array(
'authenticate' => array(
'TwitterKit.TwitterOauth',
),
),
View convert.php
<?php
$start_time = microtime(true);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<style>
@hiromi2424
hiromi2424 / daily_report.php
Created May 27, 2011
MultiSlugRoute design
View daily_report.php
<?php
class Report extends AppModel {
// set true when type => daily was affected
private $__dailyReportAffected = false;
/*
some implemetations...
*/
View app_shell.php
<?php
abstract class AppShell extends Shell {
public $Controller;
/**
* Loads a Controller in order to use features what Controller has.
*
* @return Controller loaded controller object
@hiromi2424
hiromi2424 / json_debug.php
Created Apr 21, 2011
simple json formatter(possible to use formatted)
View json_debug.php
// almost same output can be seen at:
// http://jsonformatter.curiousconcept.com/
class JsonDebug {
function format($json, $output = false) {
$depth = 0;
$length = strlen($json);
$result = '';
for ($n = 0; $n < $length; $n++) {
$c = $json{$n};
View closure_test.php
<?php
class TestClosure {
public $hoge = 'hoge';
public $piyo = 'piyo';
public $fuga = 'fuga';
public function delegate($lambda) {
return $lambda($this);
@hiromi2424
hiromi2424 / base_service.php
Created Apr 16, 2011
simple transaction service
View base_service.php
<?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.
*/