2011-11-22 70 views

回答

1

postExecute方法在每個動作調用結束時執行。
這裏是documentation

+0

這是一個模塊中的每一個動作,而不是在一個應用程序。 – greg0ire

9

您可以使用過濾器執行後,執行代碼,以及:

class myFilter extends sfFilter { 

    public function execute($filterChain) { 

     // Code that is executed before the action is executed 

     $filterChain->execute(); 

     // Code that is executed after the action has been executed 

    } 

} 

這是因爲在Symfony的完整的執行是一個大的「過濾器鏈」 ......如果你看看在您的filters.yml處,您會看到首先調用了rendering過濾器,然後是security過濾器,cache過濾器,最後是execution過濾器。 執行過濾器是實際執行請求的過濾器(調用控制器和所有內容)。

爲了說明這一點:緩存過濾器將在下鏈之前檢查緩存中是否有可用輸出,並返回該緩存。如果現在它將執行鏈中的下一個過濾器,並在返回時存儲輸出,以便後續請求可以使用高速緩存。

2

你必須在動作類中添加這個方法:

public function postExecute() 
    { 
    // do something 
    } 
相關問題