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

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter Archived (from EllisLab) (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Please give me example of returning views as data (/thread-49835.html)



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