Should work but doesn't |
[eluser]clintonbeattie[/eluser]
Hi, I have my Model, Views and Controller set up to what appears to be correct, but I keep getting "Undefined index: intro" when the page loads. Can you please look through the code and tell me what I've done wrong? I'm sure it's something simple. Thanks for any help!!! CONTROLLER Code: class Welcome extends Controller { MODEL Code: class MBlog extends Model { VIEW This is the template... Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> This is blog.php which is embedded into the template... Code: <?php
[eluser]pistolPete[/eluser]
You do not pass any data to the view "blog.php"! Code: <?php $this->load->view($main); ?>
[eluser]clintonbeattie[/eluser]
I thought this embedded the blog.php into the $main variable in my template.php page and the data could be displayed like that? Code: $data['main'] = 'blog'; Please confirm if I'm totally wrong (Which is highly likely lol) For example, if I use this code in my blog.php page it spurts out all the data... Code: <?php
[eluser]pistolPete[/eluser]
If you want to access variables in all your views, you have to use: Code: $this->load->vars($array) From http://ellislab.com/codeigniter/user-gui...oader.html: Quote:This function takes an associative array as input and generates variables using the PHP extract function. This function produces the same result as using the second parameter of the $this->load->view() function above. The reason you might want to use this function independently is if you would like to set some global variables in the constructor of your controller and have them become available in any view file loaded from any function. You can have multiple calls to this function. The data get cached and merged into one array for conversion to variables. |
Welcome Guest, Not a member yet? Register Sign In |