Sorry if my question is vague I tried to keep is as simple as possible, I am using the following controller in cakephp:
var $uses = array('Client','Ticket','Userseequeue','Queue','Task','User');
var $useTable = false;
function index() {
$clientsResult = $this->Client->find('all');
$userSeeQueuesResult = $this->Userseequeue->find('all', array('conditions' => array('Userseequeue.user_id' => '1') ) );
$ticketsResult = $this->Ticket->find('all');
$queuesResult = $this->Queue->find('all');
$tasksResult = $this->Task->find('all', array('group' => array('Task.ticket_id','Task.queue_id') ) );
$usersResult = $this->User->find('all');
$this->set(compact('tickets','userSeeQueues','clients','queuesResult','tasksResult','users','ticketUsers','ticketQueues'));
if (!empty($this->data)) {
$this->Ticket->create();
$this->Ticketsinqueue->insertData($this->data);
if ($this->Ticket->save($this->data) && $this->Ticketsinqueue->save($this->data)) {
$this->Session->setFlash(__('The ticket has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The ticket could not be saved. Please, try again.', true));
}
}
}
And I use these tables to display a summary of information on a single view.
I need to add a form on that view screen to add an additional ticket. What am i doing wrong or missing to create this form and have it save to the table?
Here is my view where I tried to create the form, in case it might help:
<div class="Summary index">
<h2><?php __('Summary');?></h2>
<?php echo $this->Form->create('Ticket');?>
<fieldset>
<legend><?php __('Add Ticket'); ?></legend>
<?php
echo $this->Form->input('Ticket.name');
echo $this->Form->input('Ticket.user_id');
echo $this->Form->input('Ticket.queue_id');
?>
<?php echo $this->Form->end(__('Submit', true));?>
</fieldset>
...
This creates the form but it does not populate the drop down list from it’s relationships’ tables correctly as it would in the normal add view created by cakephp. It currently fills the drop down list with all the tables’ I used in this controller.
I would appreciate if anyone can assist me or help me in the right direction.
I got this to work by:
Having the controller first save the data before creating the variables for the view
and saving the list of values, for each drop down, as a variable in the controller.
My view now list the values from the controller’s variables i created:
With this I can have a form to add a ticket as well as display information from other models / tables all on one page.