0
votes

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.

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. - Devon
Remove the array reference of [0] in view.php - mcv

1 Answers

3
votes

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

<?php print_r($fyfrom); ?>