2014-04-25 119 views
0

我想知道如何爲「訪問控制」添加一個值爲「staff」和「Admin」的下拉列表。 這是員工控制器我的附加功能蛋糕PHP下拉列表

public function add() { 
     if ($this->request->is('post')) { 
      $this->Employee->create(); 
      if ($this->Employee->save($this->request->data)) { 
       $this->Session->setFlash(__('The employee has been saved.')); 
       return $this->redirect(array('action' => 'index')); 
      } else { 
       $this->Session->setFlash(__('The employee could not be saved. Please, try again.')); 
      } 
     } 
    } 

這是添加視圖代碼:

<div class="employees form"> 
<?php echo $this->Form->create('Employee'); ?> 
    <fieldset> 
     <legend><?php echo __('Add Employee Details'); ?></legend> 
    <?php 
     echo $this->Form->input('employee_name'); 
     echo $this->Form->input('date_hired', array('dateFormat' => 'DMY','minYear'=>date('Y')-100, 'maxYear'=>date('Y')+100)); 
     echo $this->Form->input('employee_phone_number'); 
     echo $this->Form->input('employee_email'); 
     echo $this->Form->input('employee_address'); 
     echo $this->Form->input('employee_dob', array('dateFormat' => 'DMY','minYear'=>date('Y')-100, 'maxYear'=>date('Y')+100)); 
     echo $this->Form->input('access_level'); 
     echo $this->Form->input('employee_username'); 
     echo $this->Form->input('employee_pw'); 
    ?> 
    </fieldset> 
<?php echo $this->Form->end(__('Submit')); ?> 
</div> 
+0

你可以使用[喜歡的方式枚舉(http://www.dereuromark.de/2010/06/24/static例如-enums-or-semihardcoded-attributes /) - 使用類常量。 – mark

+0

閱讀[FormHelper]上的文檔(http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs),它有你的答案。 –

回答

1

如果你正在從數據庫ACCESS_LEVEL數據則 -

echo $this->Form->input('access_level', array('options' => array('admin' => 'Admin', 'staff' => 'Ataff'))); 
2

添加下拉列表access control,值爲staffAdmin。 在你的員工控制器添加此

$customers = $this->Employee->modelname->find('list'); 
$this->set(compact('customers')); 

view.ctp

echo $this->Form->input('access_level');