drgc9632 2013-11-13 08:16
浏览 37
已采纳

CakePHP - 输入框受限于链接的EmployeeID,来自上一页

I got 2 related tables, let say :
- employee, and
- family

they are both connected by the employeeID as the primary and foreign key. I believe you all understand this standard condition.

I have already created all the models, controllers and views using the "cake bake". Everything is okay, until when i want to add new family. The scenario is listed below :

-- on the front page, all employees are listed, along with their VIEW, EDIT and DELETE button, each.
-- i click the VIEW button on one of the employee, let say employee MAZANDRE with employeeID 123
-- i will see the detail of MAZANDRE
-- below the detail, there is one button to ADD NEW FAMILY.
-- i modified the ADD NEW FAMILY hyperlink into this

<li><?php echo $this->Html->link(__('New Family'), array('controller' => 'families', 'action' => 'add', $employee['Employee']['id'])); ?> </li>

-- then i also modified the add function in FamiliesController like this

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

    $employees = $this->Family->Employee->findById($id);

    $this->set(compact('employees'));
}

-- then i click this ADD NEW FAMILY button
-- there is one dropdown box which list ALL the employee detail (id, name, dateofbirth, gender etc).
the link shows http://x.x.x.x/hr/family/add/123

what i want is, the INPUTBOX should only list one name which is: MAZANDRE, and cannot be modified (disabled) the original one is like this echo $this->Form->input('employee_id') how should i do this ?

Appreciate your help guys :-)
Many thanks.

Regards,
Andri

  • 写回答

2条回答 默认 最新

  • doulei6330 2013-11-14 01:48
    关注

    voila ! I got my own answer. I just check this URL cakephp: find statement with 'contain'

    But thanks to Moyed Ansari, and also user2484796

    I just put these code on my FamiliesController
    the line

    $employees = $this->Family->Employee->findById($id);

    replaced by

    $employees = $this->Family->Employee->find('list',array('conditions' => array('Employee.id' => $id)));

    that's it ! :-)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题