Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Template Task can generate templated output Used in other Tasks
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
@kanonji
kanonji / cheker_for_phptag_and_linebreak.php
Created January 24, 2013 08:46
phpタグが、外側の改行を消す事が有るみたいなので、その動きをチェックする為に作りました。 markdown風のテキストにphpタグを埋め込んでる.phpファイルです。`php cheker_for_phptag_and_linebreak.php`の様に実行すると`php code`と`output`が同じになると思います。
# phpタグと改行
## phpタグ後に文字が有る場合は問題が無い
### php code
<?php echo "PHP"; ?>text
<?php echo "PHP"; ?>

CakeEventManager

CakeEventManagerについて、ソースコードを読んで分かった事を、それでも全部を読み切ってはないので、予想も含めつつまとめます。

まとめ

CakeEventManagerは、アプリケーション全体のイベントを管理する、グローバルマネージャーとしてシングルトン風に生成される。同時に、互いに干渉しない、ローカルマネージャーの生成も行える。 CakePHPのコードをgrepした所、Model, View, Controller, Dispatcherがそれぞれローカルマネージャーを持っていて、互いに干渉しない作りとなっている。ただし、グローバルマネージャーは、どのローカルマネージャーがdispatch()しても、必ずイベントを発火させる。

グローバルマネージャー

beforeSave()はModelとBehaviorのどちらが先に呼ばれるか

  public function getEventManager() {
		if (empty($this->_eventManager)) {
			$this->_eventManager = new CakeEventManager();
			$this->_eventManager->attach($this->Behaviors);
			$this->_eventManager->attach($this);
		}
 return $this-&gt;_eventManager;
@kanonji
kanonji / 20121206_CakePHP2-tiny-doc.md
Last active May 1, 2017 05:10
My tiny doc for CakePHP2CakePHP

Model

find()

Result data format

find('first')
array(
@kanonji
kanonji / Gemfile
Created November 29, 2012 08:22
Gemfile for my heroku env
# A sample Gemfile
source "http://rubygems.org"
path 'vendor/bundle'
gem "heroku"
gem "foreman"

$ npm install nroongaでエラー

エラーメッセージ

$ npm install nroonga
[Snip]
npm http 304 https://registry.npmjs.org/mkdirp/0.3.0

> [email protected] install /Users/myuser/dev/nrn/node_modules/nroonga
@kanonji
kanonji / 20121115-CakePHP2-Model_find_joins.md
Created November 19, 2012 11:07
CakePHP2でModel->find()でjoinsを使ってみた
$option = array();
$option['recursive'] = -1; 
$option['joins'][] = array(
    'type' => 'LEFT',   //LEFT, INNER, OUTER
    'table' => 'posts',
    'alias' => 'Post',    //下でPost.user_idと書くために
    'conditions' => '`User`.`id`=`Post`.`user_id`',
);
$option['conditions'] = array('Post.isPrivate' => 1);
@kanonji
kanonji / 20121119-CakePHP2-request-params.md
Last active October 13, 2015 00:18
CakePHP2のコントローラーが扱う、ブラウザからのパラメーターの取り出し方と、1系との比較。

POST data

$this->request->data['Model']['field'];
$this->request->data('Model.field');    //キーが無い場合はnull

1系では

@kanonji
kanonji / if_which.sh
Created October 23, 2012 13:30
シェルスクリプトでコマンドの有無を判別する。
#!/bin/sh
echo "Finding $1..."
# if whereis $1 >/dev/null 2>&1; then 判別出来ない。
# if type $1 >/dev/null 2>&1; then 判別出来る。
# if which $1 >/dev/null 2>&1; then 判別出来る。
if which $1 >/dev/null 2>&1; then
echo "$1 found."
else
echo "$1 not found."