简体   繁体   English

Cake PHP下拉列表

[英]Cake PHP drop down list

I would like to know how to add a drop down list for "access control" with value "staff" and "Admin". 我想知道如何为值为“ staff”和“ Admin”的“访问控制”添加一个下拉列表。 This is my add function in employee controller 这是我在员工控制器中的添加功能

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.'));
            }
        }
    }

This is the add view code: 这是添加视图代码:

<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>

To add a drop down list for access control with value staff and Admin . 使用值staffAdmin添加用于access control的下拉列表。 add this in your employee controller 将此添加到您的员工控制器中

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

and in view.ctp 并在view.ctp

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

如果您要从数据库获取access_level数据,则-

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM