你應該把函數作爲配置參數傳遞給你的插件/組件,或者getDbConfig()的結果(我認爲它不會有太大變化)。
所以:
class MyComponent extends Component
{
private $dbconfig = null;
public function initialize (array $config)
{
parent::initialize ($config);
if (isset ($config['dbconfig']))
{
$this->dbconfig = $config['dbconfig'];
}
}
}
然後,在你的控制器:
class MyController extends AppController
{
public function initialize()
{
parent::initialize();
$this->loadComponent ('My', ['dbconfig' => $this->getDbConfig()]);
}
}
如果你真的必須引用的函數,並調用它,使用variable functions。
來源
2017-03-09 14:34:15
JvO