2016-06-12 27 views
0

我是PHP和代碼點火器的新手。我使用$ this-> load-> view的第二個參數傳遞數組數據到我的視圖中,如this thread.麻煩從控制器傳遞表單標籤屬性到查看

它在所有情況下都很好,除了一個:當我嘗試傳遞我的屬性表單標籤視圖我得到的錯誤:

PHP Error was encountered

Severity: Notice

Message: Undefined variable: attributeslabel

Filename: views/testfoo_view.php

這是我的簡化代碼:

<?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); 

     } 
    } 

在視圖文件:

<?php 
echo form_open('testfoo'); 

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

爲什麼這不起作用,我怎樣才能訪問這個屬性,而不必在每個視圖文件中重複數組?

謝謝!

回答

0

將數據傳遞給數組中的視圖。

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

然後像你已經做的那樣訪問視圖中的標籤。

相關問題