使い方

ビヘイビアを使うには使用するビヘイビア名をモデルの$actsAs属性にセットします。

class Post extends AppModel { 
    var $actsAs = array('Tree'); 
    
    function doSomething($id) { 
      //childrenはTreeビヘイビアのメソッド
        $this->children($id); 
    }
} 


ビヘイビアがセットされたモデルはビヘイビアのメソッドを使う事が出来るようになります。

class PostController extends AppController { 
    var $uses = array('Post');

    function doSomething($id) { 
      //childrenはTreeビヘイビアのメソッド
        $this->Posts->children($id); 
    }
} 


ビヘイビアに初期化のためのデータも指定出来ます。

class Post extends AppModel { 
   var $actsAs = array('Tree' => array(
        'left'  => 'left_node',
        'right' => 'right_node'
    ));
    
    function doSomething($id) { 
        $this->children($id); 
    }
} 

一時的に使用する

//Controller
$this->Post->Behaviors->attach('Containable');

CakePHP Note (v1.3)

Index