【问题标题】:Kohana 3.2 - phpBB library - working with abstract methodsKohana 3.2 - phpBB 库 - 使用抽象方法
【发布时间】:2012-01-09 12:16:23
【问题描述】:

我正在尝试在 Kohana 中实现一个 phpBB 库。

我在我的模块中创建了一个供应商文件夹,并像这样加载库并初始化它:

require_once Kohana::find_file('vendor/phpbb_library', 'phpbb_library');
$phpbb = new Phpbb_library();

但是一旦库开始尝试包含 phpBB 文件:

// Include needed files
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'config.' . $phpEx);
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);

然后我收到以下错误:

ErrorException [ Fatal Error ]: Class user contains 5 abstract methods and must therefore be declared abstract or implement the remaining methods (Kohana_Session::_read, Kohana_Session::_regenerate, Kohana_Session::_write, ...)

现在包含的文件是phpBB使用的,所以显然我不能只修改它们。


已于 2012 年 1 月 2 日解决

按照Michal M 提出的解决方案,我创建了自己的 Kohana Session 类版本并将它们保存在一个模块中。我必须复制、重命名和编辑的文件是:

/system/classes/session.php
/system/classes/session/cookie.php
/system/classes/session/exception.php
/system/classes/session/native.php

/system/classes/kohana/session.php
/system/classes/kohana/session/cookie.php
/system/classes/kohana/session/exception.php
/system/classes/kohana/session/native.php

在所有文件中,主要编辑涉及将类名 Session 更改为 MySiteSession 和 Kohana_Session 更改为 Kohana_MySite_Session。尽管/system/classes/kohana 文件中变量的一些用法也需要更改名称。

现在要使用会话,我只需调用MySiteSession::instance()。

PHPBB 现在作为一个包含,因为我不再使用 Session 类。

【问题讨论】:

  • 错误被触发是因为 phpBB 和 Kohana 都有一个 Session 类。没有解决办法。
  • 怎么可能没有解决办法? CodeIgniter 允许它工作:codeigniter.com/wiki/phpBB3_library 我认为 Kohana 是 CodeIgniter 框架的偏移量。
  • 你真的成功实现了桥接吗?你能分享一下来源吗?谢谢
  • @zdmytriv 是的,我设法按照 Michal M 的建议去做,并设置了我自己的类来处理我现在使用的会话,而不是默认的 Session 类。这消除了两个系统之间的冲突。

标签: php include kohana kohana-3 abstract


【解决方案1】:

CI 有不同的类命名。所有 CI 类都以 CI_ 开头,而 Kohana 不使用任何前缀*。

我能为您想到的唯一解决方案是重构 Kohana Session 类(到处重命名)或使用 phpBB 库来实现。不过两者都不理想。


*) 澄清一下,Kohana 确实使用了Kohana_,但它们的所有类都由不带前缀的类扩展。

【讨论】:

  • 我创建了一个新的会话类并在整个站点中使用它。系统中有一处在system/classes/kohana/security 文件中也使用了Session::instance()。我不知道我是否应该改变。将尝试扩展它。
  • 确认这有效并在原始问题中添加了完整的解释。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-13
  • 1970-01-01
  • 2012-09-21
  • 1970-01-01
  • 2023-04-04
相关资源
最近更新 更多