Skip to content

Instantly share code, notes, and snippets.

@hiromi2424
hiromi2424 / categorize.php
Created September 2, 2011 02:03
preferable example for getting data method for model(behaviorized)
<?php
/**
* Available find keys:
* 'category': adding creteria with name of category.
*/
class CategorizeBehavior extends ModelBehavior {
public $defaultSettings = array(
'key' => 'category',
@hiromi2424
hiromi2424 / 01_first.php
Created September 1, 2011 21:25
preferable example for getting data method for model
<?php
class Post extends AppModel {
/**
* Usage:
* $nextPost = $this->Post->getNext(1);
*/
public function getNext($id) {
$greater = $this->find('first', array(
@hiromi2424
hiromi2424 / auto_slug_options.php
Created July 16, 2011 07:49
SlugRoute example
<?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 July 4, 2011 23:19
quick upgrade plugins or app
<?php
// Usage
// php upgrade.php on app dir or plugin root
class App {
public static function __callStatic($method, $params) {
}
@hiromi2424
hiromi2424 / AppController.php
Created July 2, 2011 06:18
TwitterKit.TwitterOauthAuthenticate design
<?php
class AppController extends Controller {
public $components = array(
'Auth' => array(
'authenticate' => array(
'TwitterKit.TwitterOauth',
),
),
<?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 13:18
MultiSlugRoute design
<?php
class Report extends AppModel {
// set true when type => daily was affected
private $__dailyReportAffected = false;
/*
some implemetations...
*/
<?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 April 21, 2011 10:39
simple json formatter(possible to use formatted)
// 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};
<?php
class TestClosure {
public $hoge = 'hoge';
public $piyo = 'piyo';
public $fuga = 'fuga';
public function delegate($lambda) {
return $lambda($this);