开发者

adding a hook in symfony for code to be executed after the page has been rendered

i'm interested in building page statistics based on the same code the sfWebDebugPanel* use. the problem is when i use it in the filter pre execution, i can't get the count of SQL queries cause none have been run so far (actions and their subsequent model calls have not yet been executed)

so when i appended my filter to the end of filters, it doesn't seem to be run at all. it looks something like:

rendering: ~
security:  ~
cache:     ~
execution: ~
statistics:
  class: myStatistics
开发者_JAVA技巧

however this works:

rendering: ~
security:  ~
cache:     ~
statistics:
  class: myStatistics
execution: ~

but doesn't return SQL queries. any suggestions?


I don't have any drawing tools at hand, but you have to look at the rendering as a two-way street... First the rendering filter is called. This does 'some things', and then calls a function which executes the security filter. In this filter your authorization is checked, if it's not all right, the request is forwarded and the filter stack is called again, if authorization is OK, the next filter in the chain is called. The cache filter returns the page from the stack if it's valid, otherwise runs the execution filter. Then when the execution filter has run, the cache filter (which called the execution filter) now has live executed data, and stores this to the cache, then the security filter is run for the latter part, etc...

So, a typical filter implementation looks like this:

  public function execute($filterChain)
  {
    doSomething();
    // Code that is called before execution.

    // Runs all down stream filters
    $filterChain->execute();

    doSomethingElse();
    // Code that is called after execution.
  }

So you want to do your statistics probably after the execution, in the doSomethingElse() part.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜