Good logic of View helper for CodeIgniter

萝らか妹 提交于 2020-01-02 10:28:09

问题



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 content/main pages (dynamic)
  • and in the end, load footer of course

Could someone point me to the solution?

Thanks a lot, in advance!


回答1:


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.




回答2:


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




回答3:


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.




回答4:


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.




回答5:


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

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



来源:https://stackoverflow.com/questions/4650957/good-logic-of-view-helper-for-codeigniter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!