CodeIgniter Forums
Please give me example of returning views as data - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Please give me example of returning views as data (/showthread.php?tid=49835)



Please give me example of returning views as data - El Forum - 03-05-2012

[eluser]Mario "St.Peter" Valentino[/eluser]
dear,

can anybody here give example about returning views as data.
i hope the full code( from controllers and view).
i'm newbie to codeigniter.
Please do me a favor


Thanks


Please give me example of returning views as data - El Forum - 03-05-2012

[eluser]Glazz[/eluser]
http://ellislab.com/codeigniter/user-guide/general/views.html

To return a view to a string you can use:
Code:
class Welcome extends CI_Controller
{
    function index()
    {
        $data_to_send['title'] = 'Your webpage title';
        $string = $this->load->view('your_file.php', $data_to_send, true);
    }
}

Is this what you need ?


Please give me example of returning views as data - El Forum - 03-05-2012

[eluser]Mario "St.Peter" Valentino[/eluser]
i still confuse. here you save views to variable $string. how i display the result ?


Please give me example of returning views as data - El Forum - 03-05-2012

[eluser]Glazz[/eluser]
with:
Code:
echo $string;

but if you don't want to save the result to a string just use
Code:
$this->load->view('your_file.php', $data_to_send);

and it will show you the view automatically


Please give me example of returning views as data - El Forum - 03-05-2012

[eluser]Mario "St.Peter" Valentino[/eluser]
ok now i understand. Thanks my friend for your explanation