2011-01-09 33 views
0

我正在使用Kohana(v3)框架,但我相信它沒有綁定到特定的框架。如何重載關機功能?

我已經基本上是一個前端,在這裏我想用Kohana中的原生Kohana::shutdown_handler()的應用程序,但我也有的一部分 - 的RESTful API - 在這裏我不想豐富多彩,HTML編碼異常報告。我想要一個純文本報告。

我想這可能的工作方式是註冊在API的控制器抽象類的構造另一關機功能,但後來我意識到register_shutdown_function()作品不同set_exception_handler()和而不是替換它增加了一個功能,關機程序。更糟的是PHP不允許「取消註冊」關閉功能,這就是我的問題所在。

怎麼辦,如果你想使用另一個關機功能而不是的一個已經註冊?

回答

1

您可以簡單地通過自定義視圖超載

views/kohana/error
並設置

 
/** 
* Initialize Kohana, setting the default options. 
* 
* The following options are available: 
* 
* - string base_url path, and optionally domain, of your application NULL 
* - string index_file name of your index file, usually "index.php"  index.php 
* - string charset  internal character set used for input and output utf-8 
* - string cache_dir set the internal cache directory     APPPATH/cache 
* - boolean errors  enable or disable error handling     TRUE 
* - boolean profile  enable or disable internal profiling    TRUE 
* - boolean caching  enable or disable internal caching     FALSE 
*/ 
Kohana::init(array(
'base_url' => '/', 
'errors' => FALSE, 
)); 
0

首先想到的是在任何其他register_shutdown_function()調用之前添加函數,並讓它調用任何必要的關閉函數,然後調用exit或die來立即結束腳本而不調用其他關閉函數。 爲了確保您的通話是第一位的,我會爲它創建一個單獨的文件並將其添加爲php.ini的auto_prepend_file
稱它爲黑客...也許。它工作嗎?我99%確定它應該。

+0

不能做`register_shutdown_function()來`早於本地發生。使用`auto_prepend_file`看起來像是絕對最後的解決方案,並且真的不認爲它會在我的應用程序中工作,因爲它會在可能導致關閉的文件加載後調用 - 太遲了。 – 2011-01-09 17:10:25

+0

這是我1%的疑問。 Kohana可以修改嗎? – 2011-01-09 17:33:59