0
votes

I am new to PHP and code igniter. I am passing arrays of data to my views, using the second parameter of $this->load->view, as shown in this thread.

It works great in all cases except one: When I try to pass the attributes of my form label to the view I get the error:

PHP Error was encountered

Severity: Notice

Message: Undefined variable: attributeslabel

Filename: views/testfoo_view.php

This is my simplified code:

<?php
  defined('BASEPATH') OR exit('No direct script access allowed');

  class Testfoo extends MY_Controller {
      function index()
      {

          $attributeslabel = array(
              'class' => 'formlabel');

          $this->load->view('header_view');
          $this->load->view('testfoo_view', $attributeslabel);

      }
  }

In the view file:

<?php
echo form_open('testfoo');

echo form_label('What is your first name?', 'first name', $attributeslabel);

Why is this not working and how can I access this attribute without having to repeat the array in each view file?

Thank you!

1

1 Answers

0
votes

Pass the data to the view in an array.

$data['attributeslabel'] = $attributeslabel;
$this->load->view('testfoo_view', $data);

Then access the label in the view as you already did.