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 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计