doumengyin0491 2011-09-10 10:59
浏览 31
已采纳

CakePHP为客户创建约会

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?

  • 写回答

1条回答 默认 最新

  • drne47241 2011-09-10 11:14
    关注

    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', ...);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line