开发者

Zend Framework - How to implement partials which contain logic

I have a layout which works fine. This layout contains several partials, which display adverts, a side column a slideshow, etc. All of these are likely to change开发者_如何学Go depending on which page (module/controller/action) of the site you are on.

What is the best way of doing this correctly? In the past I have assigned variables to my view inside my controllers, these are then passed to the partial which then displays the correct slideshow or advert. This seems ugly and not entirely correct for an MVC application.

Does anyone have any other methods of doing this?


Partials are just another view scripts.

My advice is: newer put your logic into the view scripts. Your may store the logic in:

  • models (remember, that you can create your own models, extending, or not extending the basic database models, eg. data hydrators)
  • view helpers (with parameters)
  • services (dependent on models, returning models)
  • combination of the above

Then use view helper or pass the ready data (model) to different partials.

Tip: Dependency injection is a good thing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜