开发者

When to initialize the layout & theme specific details in Zend Framework?

开发者 https://www.devze.com 2023-01-25 06:03 出处:网络
I am new to ZF, so my question might look newbish and I apologize in advance if its already answered.

I am new to ZF, so my question might look newbish and I apologize in advance if its already answered.

The sequence in which ZF execute a complete process is

1. routeStartup

2. process route

3. routeShutdown

4. dispatchLoopStartup

5. preDispatch

6. dispatch process starts

7. controller's init method

8. controller's helper's preDispatch

9. action's preDispatch

10. action

11. action's postDispatch

12. controller's helper's postDispatch

13. postDispatch

14. dispatchLoopShutdown

now there are multiple places where we can initiate + config layout & theme details. We can do it on stage 5, 7, 8 and 9. What stage is the best for this purpose.

The application will be using AJAX so if I load the layout details on stage 5, there are开发者_运维问答 lots of chances that later I will be removing the layout and sending only XML response.


It's usually best to configure your layout using the application resource plugin during bootstrap.

To disable layout whilst responding to XHR, use the AjaxContext action helper.

Edit: At what point do you know which theme you will use? If it's early enough and the required parameters are available, you could implement this using a bootstrap _init* method or custom layout app resource plugin.

Otherwise, I'd implement and register a controller action helper, setting the theme in its preDispatch override. Using the second method also gives you access to the request, therefore allowing you to make a decision based on the request method whether you bother with the layout or not. In fact, this might be a good candidate for a custom override of the AjaxContext helper itself.


You can initiate and config layout before step 1 during Bootstrap - that's the best place :)

0

精彩评论

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