2015-12-19 32 views
1

在一個相對較大的shell中,我使用了一些任務,但是在另一個任務中似乎也需要使用一個任務的某些功能(我們稱之爲主任務)。Cakephp 2在另一個任務中使用任務

那麼,我如何在另一個任務中使用任務。 CakePHP的2.x的

感謝

回答

3

使用Shell::$tasks屬性來定義你的任務應該加載額外的任務,或使用TaskCollection::load(),繳費通過Shell::$Tasks財產手動加載它們。

可以使用任務名稱通過魔術屬性訪問其他任務。

class SubTask extends AppShell 
{ 
    public $tasks = array(
     'Main' 
    ); 

    // ... 

    public function subMethod() 
    { 
     $this->Main->mainMethod(); 

     $this->Tasks->load('Other'); 
     $this->Other->otherMethod(); 
    } 

    // ... 
} 

又見

相關問題