开发者

How do I access the stash in every request in a parent controller?

开发者 https://www.devze.com 2022-12-15 00:53 出处:网络
I am trying to refactor 开发者_JAVA百科my Catalyst application and I would like to introduce a common base class for my controllers. This base controller would load some data and put some other data

I am trying to refactor 开发者_JAVA百科my Catalyst application and I would like to introduce a common base class for my controllers. This base controller would load some data and put some other data into the stash for every request. I have got some trouble getting to the stash. Simple solution would be to implement a default auto action in the base controller. This works, but I have to remember to always call the super auto in the derived controllers. This is easy to forget, is there a better solution? In other words: Is there a simple way to tap into the request processing that wouldn’t be so easy to break in the derived controllers?


I don't think you need inheritance in order to accomplish your goal. You might have other reasons why inheritance is a good idea for your application, but it seems as a rule that inheritance is generally overused when other methods of class composition would be more appropriate.

In particular for this case, Catalyst provides for this functionality by allowing you to specify an auto method in your Root controller, which will always be invoked before the auto methods of your more particular controllers for every request. No inheritance required.

0

精彩评论

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

关注公众号