如何在cakephp

时间:2015-04-22 11:22:29

标签: cakephp-2.0

我想创建一个简单的应用程序,允许即将毕业的学生注册毕业出勤。从申请表中,学生输入保存到学生表中的详细信息等待批准。然后,管理员批准该请求,并将记录插入批准的表中并从学生表中删除。如何编写批准操作以及如何将记录移动到cakephp 2.6.3中的已批准表中。 提前谢谢

1 个答案:

答案 0 :(得分:0)

我会使用同一个表来保存这些数据。使用表学生。在表中添加approved列,其中0 =未批准,1 =已批准。当学生输入数据并将其保存到学生表时,请确保approved = 0。然后,如果学生获得批准,管理员可以将此值更改为1。

// StudentsController.php
public function approve($id = null) {
    if (!$this->Student->exists($id)) {
        throw new NotFoundException(__('Invalid'));
    }
    if ($this->request->is(array('post', 'put'))) {
        if ($this->Student->save($this->request->data)) {
            $this->Session->setFlash(__('The student has been saved.'), 'default', array('class' => 'notice success'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The student could not be saved. Please, try again.'), 'default', array('class' => 'notice error'));
        }
    } else {
        $options = array('conditions' => array('Student.' . $this->Student->primaryKey => $id));
        $this->request->data = $this->Student->find('first', $options);
    }
}

应用程序/视图/学生/ approve.ctp:

<h1><?php echo __('Approve student');?></h1>
<?php echo $this->Form->create('Student'); ?>
    <?php
        echo $this->Form->input('id');
        echo $this->Form->input('approved', array('label' => __('Approve'), 'options' => array(
            '0' => __('Not approved'),
            '1' => __('Approved'),
        )));
    ?>
<?php echo $this->Form->end(array('label' => __('Save'), 'class' => 'button')); ?>

很抱歉没有回答您的确切问题,但我认为没有必要使用两张表来确定哪些人未获批准与未获批准的学生。