Welcome Guest, Not a member yet? Register   Sign In
Sharing data accross controllers
#1

[eluser]xare[/eluser]
Hello I have doubt.

Lets imagine I have a couple of controller classes. One called home and the other called contact.

There is a number of data that I want to pass to both controllers' views. For example the title of the page.

The way I know how to do it is by doing the following

file home.php

Code:
<?php

class Home extends Controller {
    
    function Home(){
        parent::Controller();
    }
    function index(){
$data['title']="Title"
$data['content']="Home Page";
$this->load->view('home',$data);
}
}
?>

Now I rewrite code for the contact controller

Code:
<?php

class Contact extends Controller {
    
    function Contact(){
        parent::Controller();
    }
    function index(){
$data['title']="Title"
$data['content']="Contact Page";
$this->load->view('contact',$data);
}
}
?>

Is there any way I can send the variable title to more than one view from a general controller. I mean when I load variables I want to be accessed by more than one view, where could I write them down so to not to copy the code in every controller?
#2

[eluser]n0xie[/eluser]
Make use of base_controller_classes: http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY
#3

[eluser]ahmed hamza[/eluser]
try tu use session class in CI it will help u to share data across the entire site




Theme © iAndrew 2016 - Forum software by © MyBB