Welcome Guest, Not a member yet? Register   Sign In
Have active tab stay highlighted
#1

[eluser]randomdriver[/eluser]
Sorry this is my first time with OOP and working with classes so bear with me.

I have a website design that has tabs, when a user is on a certain page I want the tab to be a different color than the rest so they know they are in that section. CodeIgniter.com does this with their main site "Home | Downloads | News"

In the past I would have some php code like:
Code:
$homeTab = $downloadsTab = $newsTab = 'off';
$newsTab = 'on';

This would allow me to turn the tabs off and on. Now with the MVC I am having problems getting the logic to pass from the controller to the view. Can't find a tutorial, anyone have suggestions. I try this and it doesn't work:

Controller Code
Code:
function sentbox()
    {
        
            $data['main_content'] = 'sentbox_empty';
            $data['activemenu'] = 'sentbox';
            $this->load->view('includes/template', $data);
        
    }

View Controller
Code:
<? echo $activemenu; ?>

<?php $this->load->view('includes/header'); ?>

<?php $this->load->view($main_content); ?>

<?php $this->load->view('includes/footer'); ?>

Error I get:
Message: Undefined variable: activemenu
#2

[eluser]Zeeshan Rasool[/eluser]
<? echo $activemenu; ?>
if the defined view is loaded then it should be worked.
Did you print some thing else passed from controller
i mean send a string from controller and clear the view and just print the value .
May be your view not working/loading properly
#3

[eluser]randomdriver[/eluser]
Thanks for the reply, my view does load because it says the error is line 1 of the includes/template file which is loaded on the last line of my controller.

Quote:Did you print some thing else passed from controller
i mean send a string from controller and clear the view and just print the value .

Not sure how to. The code above is the only code I have right now. As soon as I delete the first line in the view it works. So the third line where I have $main_content, works without a problem.
#4

[eluser]Zeeshan Rasool[/eluser]
[quote author="randomdriver" date="1255688162"]

Controller Code
Code:
function sentbox()
    {
        
            $data['main_content'] = 'sentbox_empty';
            $data['activemenu'] = 'sentbox';
            $this->load->view('includes/template', $data);
        
    }

View Controller
Code:
<? echo $activemenu; ?>

<?php $this->load->view('includes/header'); ?>

<?php $this->load->view($main_content); ?>

<?php $this->load->view('includes/footer'); ?>
[/quote]
ok give another data like this:
Code:
$data['main_content'] = 'sentbox_empty';
$data['activemenu'] = 'sentbox';
$data['test'] = 'Test string is here';
$this->load->view('includes/template', $data);
and print it in view like this
Code:
<?php  echo $test;?>
if it works well then, change your array param 'activemenu' to some thing else may be it work




Theme © iAndrew 2016 - Forum software by © MyBB