CakePHP 在 Shell 及其任务之间共享代码

发布于 2024-12-11 05:25:25 字数 369 浏览 3 评论 0原文

我想知道是否可以在 Shell 及其任务之间共享代码(函数和变量)。例如,假设我有以下内容:

Class MyShell extends Shell{

 var $tasks = array('MyTask');
 var $someVariable;

 function someFunction(){}
}

然后在我的任务中:

class MyTask extends Shell {
   //somehow access the someFunction() and $someVariable in here
}

这可能吗?还有,不管是不是,这不是推荐的蛋糕做法吗?谢谢你!

I'm wondering if it's possible to share code (functions and variables) between a Shell and its Tasks. For example, say I have the following:

Class MyShell extends Shell{

 var $tasks = array('MyTask');
 var $someVariable;

 function someFunction(){}
}

and then in my tasks:

class MyTask extends Shell {
   //somehow access the someFunction() and $someVariable in here
}

Is this possible? Also, whether it is or isnt, is this not the recommended cake way? Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

触ぅ动初心 2024-12-18 05:25:25

那么为什么不使用任务来扩展 shell 类,就像这样呢?

<?php
class MyTask extends MyShell {
  function taskFunction() {
    $someFunctionResult = $this->someFunction();
  }
}

Then why not extend the shell class with the task, like this?

<?php
class MyTask extends MyShell {
  function taskFunction() {
    $someFunctionResult = $this->someFunction();
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文