title: CodeIgniter: global variables in a controller
body: <p>I'm a very newbie on CodeIgniter, and while I go on I run into problems that, in the procedural coding, were easy to fix</p>
  
  <p>The current issue is: I have this controller</p>
  
  <pre><code>class Basic extends Controller {
  
      function index(){
          $data['title'] = 'Page Title';
          $data['robots'] = 'noindex,nofollow';
          $data['css'] = $this-&gt;config-&gt;item('css');
          $data['my_data'] = 'Some chunk of text';
          $this-&gt;load-&gt;view('basic_view', $data);
      }
  
      function form(){
          $data['title'] = 'Page Title';
          $data['robots'] = 'noindex,nofollow';
          $data['css'] = $this-&gt;config-&gt;item('css');
          $data['my_other_data'] = 'Another chunk of text';
          $this-&gt;load-&gt;view('form_view', $data);
      }
  }
  </code></pre>
  
  <p>As you can see, some array items repeat over and over:</p>
  
  <pre><code>$data['title'] = 'Page Title';
  $data['robots'] = 'noindex,nofollow';
  $data['css'] = $this-&gt;config-&gt;item('css');
  </code></pre>
  
  <p>Isn't there a way to make them "global" in the controller, so that I have not to type them for each function?
  Something like (but this gives me error):</p>
  
  <pre><code>class Basic extends Controller {
  
      // "global" items in the $data array
      $data['title'] = 'Page Title';
      $data['robots'] = 'noindex,nofollow';
      $data['css'] = $this-&gt;config-&gt;item('css');
  
      function index(){
          $data['my_data'] = 'Some chunk of text';
          $this-&gt;load-&gt;view('basic_view', $data);
      }
  
      function form(){
          $data['my_other_data'] = 'Another chunk of text';
          $this-&gt;load-&gt;view('form_view', $data);
      }
  
  }
  </code></pre>
  
  <p>Thnaks in advance!</p>