0

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');
    }
1
  • put all things in one array and pass in view; it's simple Commented Aug 24, 2018 at 5:47

4 Answers 4

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

in view taemplate ...

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

foreach($comments as $comm) {
...
}
Sign up to request clarification or add additional context in comments.

Comments

1
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');
}

Comments

0

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');
}

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.