Awais Goshi
Awais Goshi

Reputation: 19

pass multiple variable from controller to view in codeigniter

error in sending multiple variable from controller to view. Error produce in view

Message: Undefined variable: heading

Controller Code:

public function index()
    {
        $this->load->model('database');
        $result['a'] = $this->database->factory_view();
        $this->load->view('header');
        $heading['heading']= '<span class="float-left" style="margin-top:10px;"><h3>Machinery and Factory</h3></span>';
        $this->load->view('factory',$result,$heading);
        $this->load->view('footer');
    }

Upvotes: 0

Views: 772

Answers (4)

user7
user7

Reputation: 21

public function index()
{
    $this->load->model('database');
    $result['a'] = $this->database->factory_view();
    $this->load->view('header');
    $result['heading']= '<span class="float-left" style="margin-top:10px;"><h3>Machinery and Factory</h3></span>';
    $this->load->view('factory',$result);
    $this->load->view('footer');
}

Upvotes: 1

curiosity
curiosity

Reputation: 844

try this one out. this will work...

public function index()
    {
        $this->load->model('database');
        $data['a'] = $this->database->factory_view();
        $this->load->view('header');
        $data['heading']= '<span class="float-left" style="margin-top:10px;"><h3>Machinery and Factory</h3></span>';
        $this->load->view('factory',$data);
        $this->load->view('footer');
    }

then call the $a and $heading inside your page view.

Upvotes: 0

manish
manish

Reputation: 431

Just like this

public function index()
{
    $this->load->model('database');
    $result['a'] = $this->database->factory_view();
    $this->load->view('header');
    $result['heading']= '<span class="float-left" style="margin-top:10px;"> 
  <h3>Machinery and  Factory</h3></span>';
    $result['param_1'] = "xyz";
    $result['param_2'] = "abc";
    $this->load->view('factory',$result);
    $this->load->view('footer');
}

Upvotes: 0

Akbar Soft
Akbar Soft

Reputation: 1066

$data['posts'] = $posts;
$data['comments'] = $comments;
$this->load->view('your_view', $data);

in view taemplate ...

foreach($posts as $post) {
...
}

foreach($comments as $comm) {
...
}

Upvotes: 1

Related Questions