Welcome Guest, Not a member yet? Register   Sign In
Can views be reused from controller to controller?
#1

[eluser]rvent[/eluser]
Hello,

so i have my default controller named "web" this loads:
Code:
$this->load->view('header', $data['topmenu']);
        $this->load->view('featured');
        $this->load->view('content', $data['maincont']);

Now there is a link in the resulting page that loads up "services", will i have to recreate the "header" view from above or could i just call it again with:
Code:
$this->load->view('header');

Without any need to get all the data to form the menu?

Thanks
#2

[eluser]daniel ispas[/eluser]
You can use the same views in as many controllers you want. Make sure to pass the $data['topmenu'] to the view in the other controller too or you will have some errors.
#3

[eluser]rvent[/eluser]
Well this is where i dont get. The view is rendered then i click on the link "services", here you cant pass any data since you are calling the other class/method, i guess that other class method could call the method that make up the menu, etc..

??
#4

[eluser]daniel ispas[/eluser]
you would have something like this
Code:
function pages(){
        $data['topmenu']=array('something'=>'some other thing');
        $this->load->view('header', $data['topmenu']);
        $this->load->view('featured');
        $this->load->view('content', $data['maincont']);
     }

function services(){
        $data['topmenu']=array('something'=>'some other thing');
        $this->load->view('header', $data['topmenu']);
        $this->load->view('featured');
        $this->load->view('services', $data['services']);
}

The two functions from above can be in separate controllers.
#5

[eluser]InsiteFX[/eluser]
Code:
function pages()
{
    $data = array();

    $data['topmenu'] = array('something' => 'some other thing');
    $data['maincont'] = 'something';

    $this->load->vars($data);

    $this->load->view('header');
    $this->load->view('featured');
    $this->load->view('content');
}

function services()
{
    $data = array();

    $data['topmenu'] = array('something' => 'some other thing');
    $data['services'] = 'something';

    $this->load->vars($data);

    $this->load->view('header');
    $this->load->view('featured');
    $this->load->view('services');
}

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB