perl - How to access other controllers in your application? -


i have application several controllers dedicated each own part, say, "news", "articles" , "shop". not connected each other, should be, need insert data them, news related current shop category. have not found clean way access controllers other current 1 handling request.

the structure of modules is:

  • site.pm main project file.
  • articles.pm handles articles.
  • news.pm handles news.
  • shop.pm handles shop.

site.pm loads each of above dynamically array of module names , calls register function set routes , other things @ startup. articles, news, etc take content database, , rendered inline template, thus, can't take related news , slam them stash, not entries in shop might need information.

this theoretical answer without code.

you have database stuff decoupled actual controllers models. that's good.

so let's assume we're in shop , want show news related current product. there @ least 2 ways that.

  1. you call models directly. model news provides way news product. in shop controller displays product page. controller needs put stuff in stash templates can access it.

  2. you create method in news controller not accessible outside. make take product id , find related news articles , populate them stash. forward product page controller in shop controller. afterwards, product page controller continues. more decoupled way.

in both cases, shop template includes template knows how deal stuff in stash displaying news. might able recycle news template here.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -