I am a little confused on something. I have a base controller that has an initialize method, setting the title, and template, and a beforeExecuteRoute method that checks access.
In the beforeExecuteRoute access check, if access is not allowed, a flash is set and the request is forwarded to IndexController / indexAction.
In general, this works as expected. For example, if I am not logged in and browse to /blog/edit/1, beforeExecuteRoute is called and I am forwarded to index/index. The page title is set via initialize() and we are good. However, if I were to browse to /index/protected, beforeExecuteRoute is called and I am forwarded to index/index, but initialize() is NOT called. A forward to the same controller seems to bypass the intialize() call. Is this the expected behaviour? It wasn't quite what I expected. I assumed initialize would have been called.
So, in a more concise verbage:
Controller A to Controller B
- request restricted page /blog/edit/1
- beforeExecuteRoute fires and a flash is set. Forward to index/index
- beforeExecuteRoute fires again (new dispatch cycle), no permission issues, continue
- initialize() called in base controller setting title and template.
- works
Controller A to Controller A
- request restricted page /index/protected
- beforeExecuteRoute fires and a flash is set. Forward to index/index
- beforeExecuteRoute fires again (new dispatch cycle), no permission issues, continue
- initialize() is NOT called. no page title, no template.
- index/index displayed with no layout.
So what's the difference? I am not 100% clear on the dispatching and when objects are created and methods called.