Welcome Guest, Not a member yet? Register   Sign In
Returning views as data
#1

[eluser]Unknown[/eluser]
I am new to CI.I can't get around using this function.
Code:
$string = $this->load->view('myfile', '', true);

Could any one help me by giving me a simple example. i've read the study guide tried some codes but not working. Appreciate any help Smile

i've tried
Code:
class Site extends CI_Controller
{
    function index()
    {
        $data_to_send['title'] = 'Your webpage title';
        $string = $this->load->view('home', $data_to_send, true);
         echo $string;
    }
}


A PHP Error was encountered

Severity: Notice

Message: Undefined variable: string

Filename: views/home.php

Line Number: 12

The output is NULL.
#2

[eluser]CroNiX[/eluser]
You'd need to post your view, which is where the error message is saying the problem is (Filename: views/home.php). Most likely you are echoing $string in your view, which doesn't exist.
#3

[eluser]Unknown[/eluser]
I tried to echo $string in the controller first. The page was blank. Then i tried to echo it in the view where i got the error.
Here is my view.

Code:
<!DOCTYPE html>
&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" c charset=UTF-8"&gt;
        &lt;title&gt;&lt;/title>


        [removed][removed]
    &lt;/head&gt;
    &lt;body&gt;
  
    &lt;/body&gt;
&lt;/html&gt;





Theme © iAndrew 2016 - Forum software by © MyBB