Dynamic content in the template file |
[eluser]Kamy[/eluser]
Hi: I'm running a site on CI 2.0. All my data are inserted in a template.php file. I can extract and display data from my controllers into views within the template file without any issues. My template has a content and sidemenu section. The content area gets filled with Data from the controller. What I'd like to do now, is to display some data from the DB on the sidemenu section so it gets displayed on all pages. Not sure how to handle this, obviously I need a controller to extract data, but how could it be on all pages? Thanks in advance for your help
[eluser]haileCI[/eluser]
in all view : <div id='sidemenu'> echo $sidemenu=site_url('youcontroller/method'); </div> class Youcontroller extentds CI_Controller{ function method() { //get what you want $this->load->view('sidemenu',$data) } } i am not sure it can work, but you can try
[eluser]Kamy[/eluser]
Thanks but that doesn't work, site_url will output the URL of the specified page.... I have a controller Sidestuff, which outputs data into Sidestuff view page... I tried including that file in the sidemenu, but it didn't work either
[eluser]InsiteFX[/eluser]
Code: $data['sidemenu'] = 'Whatever'; InsiteFX
[eluser]Kamy[/eluser]
thanks, now I'm getting a Undefined variable: sidemenu error. Here's my setup: controller: Code: public function index() View: Code: <?= $sidemenu;?> Template: Code: <? $this->load->view('test_view');?> The error: Code: A PHP Error was encountered It does display the "Hi there !" line below it.... any ideas why?
[eluser]InsiteFX[/eluser]
Use full PHP tags <?php not short tags. Code: <?php echo $sidemenu;?> InsiteFX
[eluser]Kamy[/eluser]
that made no difference and it shouldn't ! Short tags are enabled on my site and work within the rest of the pages !
[eluser]InsiteFX[/eluser]
In your Controller you need to set: Code: $data['sidemenu'] = 'Something'; If this is not set and passed you will get that error! InsiteFX
[eluser]Kamy[/eluser]
It is set ! I noticed here in the forum I made the mistake of not setting it. Code: public function index() When I browse to that page directly, like : http://localhost/index.php/test The page and the data display properly. But when I try to display $data within the template file it fails. It doesn't get recognized! |
Welcome Guest, Not a member yet? Register Sign In |