CodeIgniter or PHP Equivalent of Rails Partials and Templates

后端 未结 11 1738
猫巷女王i
猫巷女王i 2020-12-30 14:13

In CodeIgniter, or core PHP; is there an equivalent of Rails\'s view partials and templates?

A partial would let me render another view fragment inside my view. I co

相关标签:
11条回答
  • 2020-12-30 14:50

    In PHP you'd use include

    0 讨论(0)
  • 2020-12-30 14:51

    My recently released Template library works in this way.

    That template library also plays nicely with my Dwoo implementation which will give your views much more power.

    0 讨论(0)
  • 2020-12-30 14:51

    Symfony does this with their partial/component setup.

    0 讨论(0)
  • 2020-12-30 14:55

    Try out Ocular - http://codeigniter.com/wiki/Ocular_Layout_Library/ - its a rails inspired templating library.

    0 讨论(0)
  • 2020-12-30 14:59

    This is unfortunately not CodeIgniter specific at all, however I suggest you to have a look at Savant3 template system. It allows you to render the template to a string. Then you can simply stuck it to wherever you wish.

    Maybe there's something like that in CodeIgniter?

    I can think of a way to add a facility when rendering the view, to render the template, and then all the sub-template it contains.

    0 讨论(0)
  • 2020-12-30 15:00

    I may be breaking some MVC rule, but I've always just placed my "fragments" in individual views and load them, CodeIgniter style, from within the other views that need them. Pretty much all of my views load a header and footer view at the top and bottom, respectively:

    <? $this->load->view( "header" ); ?>
    //Page content...
    <? $this->load->view( "footer" ); ?>
    

    The header could then include a NavBar in the same fashion, etc.

    0 讨论(0)
提交回复
热议问题