suppose I have two tables employees and accreditations and a join
table employees_accreditations.
employees_accreditations table consists of the following fields.
1.accreditation_id
2. employee_id
3.certification_number
4.issue_date
5. expiry_date
while adding following things happen:
1. when the user clicks add employee link. form is displayed which
contains-
a. all the input field of employees table
b. select box that displays the accreditation licenses name
c. certification_number, issue_date, expiry_date.
I have done adding.
but I want all the field to be displayed in edit view that is.
1. all employee details entered.
2. selected accreditation license name
3. certication_number,issue_date,expiry_date
my employees model looks like following:
class Employee extends AppModel {
var $name = "Employee";
var $hasAndBelongsToMany = array(
'Accreditation' => array('className' => 'Accreditation',
'joinTable' =>
'employees_accreditations',
'foreignKey' => 'employee_id',
'associationForeignKey'=>
'accreditation_id',
'conditions' => '',
'order' => '',
'limit' => '',
'unique' => true,
'finderQuery' => '',
'deleteQuery' => '',
)
);
EmployeesController
class EmployeesController extends AppController {
var $name = 'Employees';
var $helpers = array('Html', 'Form','Javascript');
var $components = array('RequestHandler','Tablefilter');
function index() {
if(!empty($this->data)) {
$parsedConditions = $this->Employee->parseCriteria($this->data);
$this->paginate['Employee'] = array(
'conditions' => $parsedConditions,
'fields' => 'Employee.id, Employee.first_name, Employee.surname'
);
}
$pagecontents = $this->paginate();
if (empty($pagecontents)) {
$this->Session->setFlash("No Employee matches the search Criteria
Please re-enter the search criteria again!!");
}
else {
$this->Employee->recursive = 0;
$this->set("employees",$this->paginate());
}
}
function view($id = null) {
$this->set('page_title', 'View Employee');
if (!$id) {
$this->Session->setFlash(__('Invalid Employee.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('person', $this->Employee->read(null, $id));
}
function cancelcard($id) {
$employees = $this->Employee->findById($id);
if($employees['Employee']['card_status'] == 'cancelled') {
$this->Session->setFlash("smart card has already been cancelled");
$this->redirect("/employees/view/".$id);
}
else if($employees['Employee']['card_status'] == 'inactive') {
$this->Session->setFlash("employee doesn't hold smartcard to be
cancelled");
$this->redirect("/employees/view/".$id);
}
else {
$this->data['Employee']['id'] = $id;
$this->data['Employee']['card_status'] = 'cancelled';
$this->data['Employee']['card_cancelled_date'] = date('Y-m-d');
if($this->Employee->save($this->data)) {
$this->Session->setFlash("smart card has been cancelled");
$this->redirect("/employees/view/".$id);
}
else {
$this->Session->setFlash("smartcard cannot be cancelled");
$this->redirect("/employees/view/".$id);
}
}
}
function add($id=null) {
if(!empty($this->data)) {
$this->Employee->save($this->data['Employee']);
$getid = $this->Employee->getLastInsertId();
$this->data['Accreditation']['employee_id'] = $getid;
$this->Employee->EmployeesAccreditation->save($this-
>data['Accreditation']);
$this->Session->setFlash('New Employee Added');
$this->redirect(array('action'=>'index'));
}
else {
$list=$this->Employee->Accreditation->findAll();
$accreditationArray=Set::combine($list,"{n}.Accreditation.id","{n}.Accreditation.name");
$this->set('accreditationList',$accreditationArray);
}
}
function delete($id = null) {
if(!$id) {
$this->Session->setFlash(__('No Employee exists'));
$this->redirect(array('action'=>'index'));
}
if($this->Employee->del($id)) {
$this->Session->setFlash('Employee Deleted');
$this->redirect(array('action'=>'index'));
}
}
function edit($id=null) {
if(!empty($this->data)) {
}
else {
$this->Employee->EmployeesAccreditation-
>bindModel(array('belongsTo' => array('Employee', 'Accreditation')));
}
}
}
?>
edit view.
<div>
<fieldset>
<legend><?php __('Edit Employee'); ?></legend>
<?php
echo $form->create('EmployeesAccreditation');
echo $form->input('id');
echo $form->input('card_no');
echo $form->input('card_expiry_date',array('type'=>'date'));
echo $form->input('first_name');
echo $form->input('surname');
echo $form->input('date_of_birth');
echo $form->input('street_no_and_name');
echo $form->input('suburb');
echo $form->input('state');
echo $form->input('post_code');
echo $form->input('telephone_number');
echo $form->input('mobile_number');
echo $form->input('driving_license_number');
echo $form->input('position_title');
echo $form->input('employer_company_name');
echo $form->input('employer_contact_person_name');
echo $form->input('employer_department');
echo $form->input('employer_telephone_number');
echo $form->input('employer_mobile_number');
echo $form->input('employer_fax_number');
echo $form->input('employer_email_address');
echo $form->input('employer_street_no_and_name');
echo $form->input('employer_po_box');
echo $form->input('employer_suburb');
echo $form->input('employer_state');
echo $form->input('employer_post_code');
echo $form->input('allergy_description');
echo $form->input('sub_category',
array('type'=>'select','options'=>array('M'=>'M')));?>
<legend><?php __('Edit Accreditations'); ?></legend>
<?php
echo $form->input('Accreditation.accreditation_id',
array('type'=>'select','options'=>$accreditationList));
echo $form->input('Accreditation.certification_number');
echo $form->input('Accreditation.issue_date');
echo $form->input('Accreditation.expiry_date');
echo $form->input('Accreditation.due_date_assignments');
echo $form->submit('Edit');
echo $form->end();
?>
</fieldset>
</div>
thankyou
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment