Loading views within views |
[eluser]TheFuzzy0ne[/eluser]
Hi. I'm wondering if anyone can offer me a more elegant solution to the one I have. I have a main template which is loaded, and within that template, I echo the contents, and sidebar. My controller code looks something like this: Code: $content_data['title'] = 'Recommended Resources'; That looks quite messy to me, and I will probably need to add more variables at some point also. Does that look right, or is it overkill? Many thanks in advance.
[eluser]xwero[/eluser]
I'm a big fan of the vars method but then you have to be careful later variables don't overwrite the older. Your code can look like this Code: $this->load->vars(array(
[eluser]pistolPete[/eluser]
You could have a look at the numerous "template/layout libraries": - http://www.williamsconcepts.com/ci/codei.../template/ - http://codeigniter.com/wiki/View_Object_PHP5 - http://codeigniter.com/wiki/View_Object/ And so on...
[eluser]TheFuzzy0ne[/eluser]
Thanks for the replies, guys. I'd like to avoid using a library if possible, as it's probably overkill for what I need. I had no idea $this->load->vars() was so powerful... I think I'll use that. Thanks again, guys!
[eluser]TheFuzzy0ne[/eluser]
Ack! $this->load->vars() is not working. The views are being loaded before the variables have been unpacked.
[eluser]TheFuzzy0ne[/eluser]
I think the calls to $this->load->view() should come after the call to $this->load->vars().
[eluser]pistolPete[/eluser]
I don't want to be rude, but you do know there is an edit button?
[eluser]TheFuzzy0ne[/eluser]
I just needed to call $this->load->vars() twice: Code: $this->load->vars(array(
[eluser]TheFuzzy0ne[/eluser]
[quote author="pistolPete" date="1235424511"]I don't want to be rude, but you do know there is an edit button? [/quote] Yes I do, but you two guys seem to be on the ball today, so I didn't want you both to miss any edits I made. Your comment is duly noted.
[eluser]xwero[/eluser]
Ah yes i know why this happens. The view method is executed in the controller before the vars method has a chance to add the variables. I changed the vars method a bit Code: function vars($vars = array(), $val = '') Code: $this->load->vars(array( |
Welcome Guest, Not a member yet? Register Sign In |