VIEW WITHIN VIEW - CAN'T GET IT TO WORK |
[eluser]Barwick[/eluser]
Hey guys, But of a CI newbie here, so trying to figure out the small sh*t that's probably super simple. I'm trying to create some clean code and structure for my application. I have a header_view that I've posted below. But instead of layout out all the js and css scripts in this view, I wanted to point to another from the controller - a view within a view. I've read numerous posts on here and couldn't figure it out. What am I doing wrong? I have a variable in the header_view below called $scripts. In my controller, I'm trying to pass through the scripts_view to the variable in my header...I'm assuming I'm not doing something right in controller (which I've also pasted below). Note, I don't want to use a template system. Just want an organized application. header_view.php: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Controller: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Any help would be greatly appreciated boys and girls! love the framework so far - but still trying to hammer it down! Cheers, Mike
[eluser]harshitha[/eluser]
why this way, what I mean is, why you need to use view within view?
[eluser]michalsn[/eluser]
Code: $data['scripts'] = $this -> load -> view('scripts_view', '', true);
[eluser]Barwick[/eluser]
[quote author="harshitha" date="1351057399"]why this way, what I mean is, why you need to use view within view?[/quote] I suppose I don't need to for this particular incident - I just like things separated and organized. Plus diff scripts will need to be loaded further down the road. I'll need to embed a view within a view, so I thought I'd ask and learn now.
[eluser]Barwick[/eluser]
[quote author="rochellecanale" date="1351064211"]Try to use iframe[/quote] Funny guy...everyone loves a forum clown, yeah?
[eluser]Barwick[/eluser]
[quote author="michalsn" date="1351064605"] Code: $data['scripts'] = $this -> load -> view('scripts_view', '', true); I had this originally - and figured this would be the correct function. But nope, still getting an error. Here's the error message... FYI: Line 9 is <?php echo $scripts; ?> on the view. Code: A PHP Error was encountered
[eluser]Barwick[/eluser]
[quote author="michalsn" date="1351064605"] Code: $data['scripts'] = $this -> load -> view('scripts_view', '', true); So what I had originally, and what you posted above, is absolutely correct. I'm just an idiot and didn't paste it in all the controllers. Which brings up a new question - would a helper be a good idea to load this across all controllers? Without having to go in and do this for each?
[eluser]michalsn[/eluser]
If you need it in all your controllers just extend CI_Controller. More info about extending native libraries: http://ellislab.com/codeigniter/user-gui...aries.html Example: Code: class MY_Controller extends CI_Controller In your controllers use then $this->data Code: $this->data['title'] = 'Dashboard'; |
Welcome Guest, Not a member yet? Register Sign In |