• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem array in my view...

#1
[eluser]Unknown[/eluser]
Hello,

I begin on codeigniter and I have a problem.

In my view, I have:

Quote:Severity: Notice

Message: Undefined variable: data

In my controller:

Code:
class JobName extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper(array('form', 'url'));
        $this->load->model('user_model');
        $this->load->view('_partials/header');
        $this->load->view('_partials/footer');
    }

    public function index() {
        $data = $this->user_model->getNameJob();
        if (!is_array($data)) {
            $data = array();
        }
        var_dump($data);
        $this->load->view('listJob', array('listjob' => $data));
    }

}

And in my model :

Code:
public function getNameJob() {
        $query = $this->db->get('namejob');
        return $query->result_array();
    }

Could you help me?

Thanks a lot !

#2
[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

I assume that's an error coming from your view -- which, coincidentally, you didn't post?

$data is not available within your view. The values are.

For example, with the following data variable:
Code:
$data = array(
    'user_id' => '151',
    'username' => 'thefuzzy0ne',
);

Within your view, you would have access to this data as $user_id and $username.

If you want to access the array itself, you'd need to load your view like this:
Code:
$this->load->view('listJob', array('data' => $data));

That way, the $data array is extracted into the global scope of the views.

For further information, please see http://php.net/manual/en/function.extract.php

A tip for the future: Please post the entire error message. It helps us to see where the error is, otherwise we have to waste time guessing, or worse yet, some people might not even bother to help you at all. Smile

#3
[eluser]Unknown[/eluser]
Sorry, I just did a var_dump. Smile

it works, thank you so much!!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.