【问题标题】:CakePHP - Trouble extending __construct functionCakePHP - 扩展 __construct 函数时遇到问题
【发布时间】:2012-08-09 06:08:42
【问题描述】:

我目前正在尝试通过 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);
}

如果我在 ExtendedFormAuthenticate.php 中使用上述 __construct,我会收到错误消息 syntax error, unexpected T_VARIABLE

public function __construct()
{
    parent::__construct($collection, $settings);
}

如果我在 ExtendedFormAuthenticate.php 中使用上述 __construct,我会收到 undefined variable 错误消息,因为我没有填充这些变量,但我不知道用什么填充它们。

有谁知道如何成功扩展 BaseAuthenticate.php 构造函数?或者,有谁知道如何声明要在类中使用的对象,而不是在 __construct 函数中?

【问题讨论】:

    标签: php cakephp


    【解决方案1】:

    尝试改变这个:

    public function __construct()
    {
        parent::__construct(ComponentCollection $collection, $settings);
    }
    

    到这里:

    public function __construct(ComponentCollection $collection, $settings)
    {
        parent::__construct($collection, $settings);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-03
      • 1970-01-01
      • 2019-10-16
      相关资源
      最近更新 更多