CodeIgniter Forums
Loading multiple views from a single array - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Loading multiple views from a single array (/showthread.php?tid=37737)



Loading multiple views from a single array - El Forum - 01-19-2011

[eluser]phpgeek[/eluser]
Hello everyone, is it possible to load multiple views from an array of filenames? I've tried it but i had no luck, here is the code:

Code:
//I'd like to do this
$pages= array('header', 'instrucciones_base', 'welcome_message', 'form_base', 'footer');
$this->load->view($pages);


//Rather than this
$this->load->view('header');
$this->load->view('instrucciones_base');
$this->load->view('welcome_message');
$this->load->view('form_base');

The error that shows is:
A PHP Error was encountered

Severity: Warning

Message: pathinfo() expects parameter 1 to be string, array given

Filename: libraries/Loader.php

Line Number: 608


Loading multiple views from a single array - El Forum - 01-19-2011

[eluser]James Bolongan[/eluser]
Yes its possible :-)

Try this:


Code:
$pages= array('header', 'instrucciones_base', 'welcome_message', 'form_base', 'footer');
foreach($pages as $pages)    {
    $this->load->view($pages);
}



Loading multiple views from a single array - El Forum - 01-19-2011

[eluser]phpgeek[/eluser]
Sweet! thanx!