Welcome Guest, Not a member yet? Register   Sign In
Problem array in my view...


I begin on codeigniter and I have a problem.

In my view, I have:

Quote:Severity: Notice

Message: Undefined variable: data

In my controller:

class JobName extends CI_Controller {

    public function __construct() {
        $this->load->helper(array('form', 'url'));

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


And in my model :

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

Could you help me?

Thanks a lot !

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:
$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:
$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

Sorry, I just did a var_dump. Smile

it works, thank you so much!!

Theme © iAndrew 2016 - Forum software by © MyBB