S. Shaker
S. Shaker

Reputation: 3

Passing array data to view from controller in CodeIgniter

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.

Upvotes: 0

Views: 148

Answers (1)

mrbm
mrbm

Reputation: 2194

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

<?php print_r($fyfrom); ?>

Upvotes: 3

Related Questions