我在關注Symfony 2網站上的How to Override any Part of a Bundle頁面。這很有趣:擴展Symfony 2請求服務?
您可以通過在應用程序/配置/ config.yml設置抱着它服務的類名的參數設置爲自己的 類。當然,如果類名稱被定義爲包含該服務的包的服務 配置中的參數,則這當然只有 。
所以我看着/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config
我發現session.xml
被定義%session.class%
參數,所以它應該是很容易的東西,如延長的Symfony Session
類:
namespace Acme\HelloBundle\Component\HttpFoundation;
use Symfony\Component\HttpFoundation\Session;
class ExtendedSession extends Session
{
public function setSuccessFlashText($text, array params = array())
{
parent::setFlash('success', $this->getTranslator()->trans($text, $params);
}
}
我din't測試這個呢。但是我怎樣才能做到與request
特殊服務一樣呢?我想添加一些便捷的快捷方式以使我的代碼更易於閱讀。
<!--
If you want to change the Request class, modify the code in
your front controller (app.php) so that it passes an instance of
YourRequestClass to the Kernel.
This service definition only defines the scope of the request.
It is used to check references scope.
-->
<service id="request" scope="request" synthetic="true" />
這裏是我的app.php
:
我services.xml
文件中發現這一點。我應該如何傳遞我的自定義請求類的實例?
require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
use Symfony\Component\HttpFoundation\Request;
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
$kernel->handle(Request::createFromGlobals())->send();
'網/ app.php' - 你不有這樣的? O_o – 2012-08-06 06:18:51
@thecatontheflat lol:D我正在看'/ app'文件夾...然後我要更新這個問題。 – gremo 2012-08-06 06:23:11