I have 3 database tables like rooms, room_type and room_status. Here is the tables` structure
rooms
room_id, room_number, room_type_id, room_status_id
room_type
room_type_id, room_type_name, room_type_desc
room_status
room_status_id, room_status_name, room_status_desc
So, Actually based on this tables need to create form to add new room. I already has created rooms controller and model.
My thought is to create form based on the rooms table and create another two controller for room_type and for room status. After that get data from room_type and room_status and pass it to room form where i can create select element using this data.
Can you advice how can I achieve better solution. I am not that sure that this is good solution.
[EDIT]
`$status = $this->createElement(‘select’, ‘status’);
$status->setLabel("Select a status:");
$status->addMultiOption('Active', 'active');
$status->addMultiOption('Suspended', 'suspended');
$this->addElement($status);`
As you can see here addMultiOptionis static, how to make it dynamic from the database? I hope I could explain you my idea?
If I understand what you are trying to do, and I’m not sure I do. Setting Type and Status via a form would work in certain situations.
First thing you might want to do would be to add a
room_status_idto yourroomtable, so you can track current status.I’m imagining your context is a hotel or convention center type setting. In this context the room type will likely not change frequently, but the status may change several times a day.
So doing a form in like an admin console to setup the room and make initial type and status designations and the occasional change would be appropriate. For day to day operations you might want to include automatic status changes in your various controller actions.
Some psuedo code for example:
you probably don’t need a controller for room_type and room_status as this info is unlikely to be changed or manipulated a lot.
room_type and room_status seem like they will be the kind of data that get set initially and then rarely change values. If that is the case the model would be the place to access these values and then just pass them where needed.
I hope I haven’t missed the point completely.
[EDIT]
You asked how to display the names of room_type and room_status in your comment. You’d use a join:
[EDIT]
To display a select form element based on a db table: