CodeIgniter Forums

Full Version: Problem array in my view...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum


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 !

El Forum

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

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

El Forum

Sorry, I just did a var_dump. Smile

it works, thank you so much!!