开发者

Good logic of View helper for CodeIgniter

开发者 https://www.devze.com 2023-02-03 17:32 出处:网络
Could someone tell what is good logic for creating custom helper for Views? What I would like to accomplish is...

Could someone tell what is good logic for creating custom helper for Views?

What I would like to accomplish is...

  • load header
  • load main navigation (static for all pages)
  • load some widgets etc. (static for all pages)
  • load co开发者_运维百科ntent/main pages (dynamic)
  • and in the end, load footer of course

Could someone point me to the solution?

Thanks a lot, in advance!


This question gives some explanation to the method dqhendricks describes. It includes code examples showing how to use $this->load->view() to return the view to a variable instead of outputting it to the browser, how to include sub-views, and using a specific view as your main template. It's the best way I've found of handling view logic. Getting the hang of CodeIgniter - Templating / loading views


Some people will create a master template, then pass the sub content's view name in the data object. The master template will call the header view, footer view, etc, and use the data array to dynamically display the correct sub content view.


For a Template library that is more actively developed than Collin's (linked by predrag.music) try out mine:

https://github.com/philsturgeon/codeigniter-template

His is good but this supports modules, themes, mobile version variations of themes and plenty more.


you could use inheritance chaining (with a custom controller class or with an included extra class that extends controller that you extend from your controllers instead of the controller class) to make a common controller hub for all pages that has a method for the top stuff, and a method for the bottom stuff.


If you need something for the reference this one is good:

http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html

0

精彩评论

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

关注公众号