2014-05-08 32 views

回答

2

做正確的方法是使用getState()方法

$state = $crud->getState(); 

if ($state == 'export' || $state == 'print') { 
    $crud->columns('first_name','last_name','email'); 
} else { 
    $crud->columns('first_name','last_name','email','phone','city','country'); 
} 

下面你可以找到一個完整的代碼示例:

function example1() 
{ 
    $crud = new grocery_CRUD(); 

    $crud->set_table('customers'); 
    $crud->set_subject('Customer'); 
    $crud->required_fields('first_name', 'last_name','email'); 

    $state = $crud->getState(); 

    if ($state == 'export' || $state == 'print') { 
     $crud->columns('first_name','last_name','email'); 
    } else { 
     $crud->columns('first_name','last_name','email','phone','city','country'); 
    } 

    $output = $crud->render(); 

    $this->_example_output($output); 
} 
+0

這給了我錯誤使用未定義的常量狀態 - 假設'狀態' –

+0

是的,對不起。我剛編輯了代碼。感謝那 –