0

Here is my controller function code:

         public function dispcp(){
            $data = array(
            'company' => $this->input->post("company"),
            'fyfrom' => $this->input->post("fyfrom"),
            'fyto' => $this->input->post("fyto"),
          );   

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

Here the data comes from a form from another view.

this is what my code in view.php looks like :
<?php print_r ($data[0]->fyfrom); ?>

Error:
Message: Undefined variable: data

Filename: views/view.php

Line Number: 14

Backtrace:

File: C:\wamp\www\admin\application\views\view.php Line: 14 Function: _error_handler

File: C:\wamp\www\admin\application\controllers\Dashboard.php Line: 586 Function: view

File: C:\wamp\www\admin\index.php Line: 263 Function: require_once

Works correctly in Controller, not in view.

2
  • 1
    $data is what you named the payload in the controller, the name of variables aren't passed when you call a function. The view will extract what you passed into their own variables, like in mrbm's answer. You also have no 0 key and you're accessing an array like an object so you have quite a few concerns in your attempt. It might be better to do some more reading. Commented Mar 26, 2018 at 20:38
  • 1
    Remove the array reference of [0] in view.php Commented Mar 26, 2018 at 20:38

1 Answer 1

3

Once the data is passed to the view you need to use the array keys are variables directly :

<?php print_r($fyfrom); ?>
Sign up to request clarification or add additional context in comments.

2 Comments

for example: echo $company
Worked very well Thanks

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.