开发者

CakePHP create appointment for client

I am building a simple booking system in CakePHP that uses 3 tables to create bookings. They are Clients, Doctors and Appointments. A client and a doctor can have multiple appointments, but an appointment can only have one client and one doctor.

I have built the create and edit client parts fine but struggling to build the create appointment and link them to a doctor and开发者_开发百科 client. I have set up the relationships in the Models and they work fine for pulling data out so I know they work as intended.

So for example if I want to book an appointment for client with ID of 1 I would visit: /appointments/add/1 And then in the view it will have something like:

   <h1>Book Appointment <em>for</em> <?php echo $client['Client']['firstname'] . " " . $client['Client']['lastname']; ?></h1>

<?php echo $this->Form->create('Appointment', array('url' => array('admin'=>true,'controller'=>'appointments','action'=>'add',$client_id))); ?>

    <fieldset id="post-form">
        <ul>
            <li>
                <?php echo $this->Form->input('client_id', array('type' => 'hidden','value'=>$client_id)); ?>

                <?php echo $this->Form->input('doctor_id', array('label' => '<strong>Choose Doctor</strong>',$doctors)); ?>
            </li>
            <li>
                <?php echo $this->Form->input('datetime', array('label' => '<strong>Date and Time</strong>')); ?>
            </li>
            <li>
                <?php echo $this->Form->input('treatment', array('label' => '<strong>Treatment</strong>')); ?>
            </li>
            <li class="sep clearfix">
                <input class="submit" type="submit" name="submit" value="Book Appointment" />
            </li>
        </ul>
    </fieldset>

    <?php echo $this->Form->end(); ?>

So as you can see I want to display the name of the client in the header using the passed id (which is called client_id in the appointments table). And you should be able to choose a doctor name from a drop down.

This is my controller action so far:

function admin_add($client_id)
{
    $this->set('client_id', $client_id);

    $this->set('doctors', $this->Appointment->Doctor->find('list'));

    if (!empty($this->data))
    {
        if ($this->Appointment->save($this->data))
        {
            $this->Session->setFlash('Your post has been saved.');
            $this->redirect(array('admin' => true, 'controller' => 'appointments', 'action' => 'index'));
        }
    }
}

However my list of doctors is NOT being created... Can anyone help? Thanks

EDIT: also noticed that everytime I submit the form it overrides the same appointment everytime with the ID of 1. SO it doesn't create a NEW appointment... any ideas?


Your client name is not displayed because you are not setting the client data in your controller.

$this->set('client', $this->Appointment->Client->find('first', array('conditions' => array('Client.id' => $client_id))));

Not sure, if this will solve the missing doctors' list problem, but you're missing the model name in the create method

$this->Form->create('Appointment', ...);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜