Cakephp 2 在另一个任务中使用任务
Cakephp 2 use task in another task
在一个比较大的shell中,我使用了一些任务,但是似乎有必要在另一个任务中也使用一个任务(我们称之为主任务)的某些功能。
那么,我如何在另一个任务中使用一个任务。 Cakephp 2.x
谢谢
使用 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();
}
// ...
}
另见
在一个比较大的shell中,我使用了一些任务,但是似乎有必要在另一个任务中也使用一个任务(我们称之为主任务)的某些功能。
那么,我如何在另一个任务中使用一个任务。 Cakephp 2.x
谢谢
使用 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();
}
// ...
}
另见