如何从bootstrap访问当前请求?

时间:2011-12-22 03:52:56

标签: request kohana-3 bootstrapping

是否可以在Kohana的bootstrap中访问当前请求?我尝试访问Request::$current,但$current似乎没有在该阶段定义。那有什么办法吗?此外,在应用程序中的哪一点定义了Request::$current

2 个答案:

答案 0 :(得分:3)

这是不可能的,因为在包含bootstrap.php后, index.php 中创建了Request对象:

// Bootstrap the application
require APPPATH.'bootstrap'.EXT;

/**
 * Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO'].
 * If no source is specified, the URI will be automatically detected.
 */
$request = Request::factory();

如果您必须访问它,请在创建后在 index.php 中执行此操作,尽管您可以告诉我们您到底想要做什么?

答案 1 :(得分:1)

您可以在Kohana初始化后使用它。

  

的Kohana ::初始化(...);

此外,良好的做法是使用接口方法而不是公共变量。我想知道为什么开发人员将$ current保持为公共领域。

所以..使用

  

支持::电流();

此外,似乎使用

  

支持::初始();

更好的主意。但这取决于你的实现。