1 2 3 4 5 6 7 8 9 10 11 12 13 14 | class UtilsComponent extends Object { private $controller ; public function initialize(& $controller ) { $this ->controller = $controller ; } function pdate( $id ) { //コントローラーのusesにあるもの $tmp = $this ->controller->Picture->read( 'modified' , $id ); return $tmp [ 'Picture' ][ 'modified' ]; } } |
しかし、呼び出し元のコントローラでusesしていないとエラーになってしまう。
それでもう一つの方法である。controller::loadModel()を使うのだがこれは コントローラーでしか使えないみたいなので同じ動きをする ClassRegistry::init()を使う。
その場合は
1 2 3 4 5 6 7 | class UtilsComponent extends Object { function pdate( $id ) { $Picture = ClassRegistry::init( 'Picture' ); $tmp = $Picture ->read( 'modified' , $id ); return $tmp [ 'Picture' ][ 'modified' ]; } } |