CodeIgniter Forums
Data sending problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Data sending problem (/showthread.php?tid=60196)



Data sending problem - El Forum - 02-04-2014

[eluser]Bigil Michael[/eluser]
I want to pass some data in all methods of demo controller. So i created a function in constructor and load that data in that function. please refer the below example

Code:
<?php
class Demo extends CI_Controller{

function demo(){
  parent::__construct();
  //
  $this->get_common();  
}
function add(){
.
.
$this->load->view('view name', $data);
}
function edit() {
.
.
.
$this->load->view('view name', $data);
}
....
..
..
function get_common(){    
  $data['test'] = "Some text message";
}
}

It is not working.
Code:
If I replace $data with $this->data , it works fine.

can any one solve this issue??



Data sending problem - El Forum - 02-04-2014

[eluser]InsiteFX[/eluser]
And where did you define your $data array at?



Data sending problem - El Forum - 02-04-2014

[eluser]Bigil Michael[/eluser]
in constructor. like this
Code:
function demo(){
  parent::__construct();
  //
  $data = array();
  $this->get_common();  
}



Data sending problem - El Forum - 02-04-2014

[eluser]InsiteFX[/eluser]
Code:
<?php
class Demo extends CI_Controller {

    $data = array();

    function __construct()
    {
        parent::__construct();

        $this->get_common();
    }

    function demo()
    {
        $this->get_common();  
    }

    function add()
    {
        ...

        $this->load->view('view name', $this->data);
    }

    function edit()
    {
        ...

        $this->load->view('view name', $this->data);
    }

    function get_common()
    {
        $this->data['test'] = "Some text message";
    }

}



Data sending problem - El Forum - 02-07-2014

[eluser]Bigil Michael[/eluser]
Thanks.