Welcome Guest, Not a member yet? Register   Sign In
write_view method: "Undefined variable"
#1

[eluser]mr. echo[/eluser]
Hello,

I'm using ci 1.7.1 and Template 1.4.1.

I set up a new contoller like this:
Code:
class Page extends MY_Controller {
    function index()
   {
    $this->template->write_view('content','test', 'Hello World');
    $this->template->render();
   }
  
}
My views/test.php looks like this:
Code:
<h1>TEST</h1>
&lt;?echo $content ?&gt;
When loading index.php/page I get this error message:
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: content

Filename: views/test.php

Line Number: 2
What did I do wrong? Why isn't &lt;?echo $content ?&gt; in test.php working?

Thanks!
#2

[eluser]TheFuzzy0ne[/eluser]
The third parameter should be an array, that much I'm sure of. Something like:
Code:
$this->template->write_view('content','test', array('content' =>'Hello World'));
#3

[eluser]mr. echo[/eluser]
Great! That's the solution. Works fine now. :-) Thanks TheFuzzy0ne!




Theme © iAndrew 2016 - Forum software by © MyBB