0

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

4

2 回答 2

0

请试试这个

  echo $this->Form->input('employee_id',array('readonly','value' => 'MAZANDRE'));

这将使输入字段成为只读值,并且该值将通过表单提交。

于 2013-11-13T11:07:28.260 回答
0

瞧!我得到了我自己的答案。我只是检查这个 URL cakephp: find statement with 'contain'

但感谢 Moyed Ansari 和 user2484796

我只是将这些代码放在我的 FamiliesController


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

取而代之

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

而已 !:-)

于 2013-11-14T01:48:26.953 回答