我目前正在尝试通过FormAuthenticate类在CakepPHP(在cake\lib\Cake\Controller\Component\Auth
文件夹中)扩展BaseAuthenticate类,我在扩展构造函数时遇到了麻烦.
我正在尝试扩展构造函数以声明一个可以在整个类中使用的新对象.
//BaseAuthenticate.php
public function __construct(ComponentCollection $collection, $settings) {
$this->_Collection = $collection;
$this->settings = Hash::merge($this->settings, $settings);
}
//ExtendedFormAuthenticate.php
public function __construct()
{
parent::__construct(ComponentCollection $collection, $settings);
}
Run Code Online (Sandbox Code Playgroud)
如果我在ExtendedFormAuthenticate.php中使用上面的__construct,我会收到错误消息 syntax error, unexpected T_VARIABLE
public function __construct()
{
parent::__construct($collection, $settings);
}
Run Code Online (Sandbox Code Playgroud)
如果我在ExtendedFormAuthenticate.php中使用上面的__construct,我会收到undefined variable
错误消息,因为我没有填充这些变量,但我不知道填充它们的内容.
有谁知道我如何成功扩展BaseAuthenticate.php构造函数?或者,有没有人知道如何声明一个对象在一个类中使用而不在__construct函数中?
尝试改变这个:
public function __construct()
{
parent::__construct(ComponentCollection $collection, $settings);
}
Run Code Online (Sandbox Code Playgroud)
对此:
public function __construct(ComponentCollection $collection, $settings)
{
parent::__construct($collection, $settings);
}
Run Code Online (Sandbox Code Playgroud)