Welcome Guest, Not a member yet? Register   Sign In
Data sending problem
#1

[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??
#2

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

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

[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";
    }

}
#5

[eluser]Bigil Michael[/eluser]
Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB