2013-08-07 3 views
-1

Neebe в cakephp пытается создать простую систему appoiment. Моя проблема заключается в том, чтобы заполнить имя Pacient только именами пользователей, принадлежащих к текущему журналу пользователя. Но если я использовал find ('list'), я получаю все pacient для всех пользователей.CakePhp принадлежит для ввода

здесь приведена таблица базы данных;

1 - для пациента

CREATE TABLE IF NOT EXISTS `Doctor_Appointments`.`pacients` (
`id` CHAR(36) NOT NULL , 
`name` VARCHAR(45) NULL , 
`user_id` CHAR(36) NOT NULL , 

2 - Пользователи

CREATE TABLE IF NOT EXISTS `Doctor_Appointments`.`users` (
`id` CHAR(36) NOT NULL , 
`username` VARCHAR(65) NULL , 
`email` VARCHAR(65) NULL , 
`password` VARCHAR(65) NULL , 

3 - Назначения

CREATE TABLE IF NOT EXISTS `Doctor_Appointments`.`appointments` (
`id` CHAR(36) NOT NULL , 
`pacient_id` VARCHAR(45) NULL , 
`date` DATETIME NULL 

Pacient Модель

public $belongsTo = array(
    'User' => array(
     'className' => 'User', 
     'foreignKey' => 'user_id', 
     'conditions' => '', 
     'fields' => '', 
     'order' => '' 
    ) 
); 

Appoiment Модель

public $belongsTo = array(
    'Pacient' => array(
     'className' => 'Pacient', 
     'foreignKey' => 'pacient_id', 
     'conditions' => '', 
     'fields' => '', 
     'order' => '' 
    ) 

Назначения/add.ctp

<?php echo $this->Form->create('Appointment'); ?> 
<fieldset> 
<legend><?php echo __('Add Appointment'); ?></legend> 
<?php 
echo $this->Form->input('date'); 
echo $this->Form->input('pacient_id'); 

Проблема должна быть здесь, в AppointmentsController

public function add() { 
    if ($this->request->is('post')) { 

     $this->Appointment->create(); 
     $this->request->data['appointment']['user_id'] = $this->Auth->user('id'); //Added this line 
     if ($this->Appointment->save($this->request->data)) { 
      $this->Session->setFlash(__('The appointment has been saved')); 
      $this->redirect(array('action' => 'index')); 
     } else { 
      $this->Session->setFlash(__('The appointment could not be saved. Please, try again.')); 
     } 
    } 

    $foo = $this->Auth->user('id'); 
    $pacients = $this->Appointment->Pacient->findAllByUserId($foo, array('Pacient.name') , array("Pacient.name" => 'desc')); 
    pr($pacients); 

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

} 

-ц ($ для пациента) дает мне слишком Муха данным увидеть ниже

Array 
(
[0] => Array 
    (
     [Pacient] => Array 
      (
       [name] => samuel Giani 
       [id] => 520178db-aa94-40d2-86e9-4fc38e7a58df 
      ) 

     [Appointment] => Array 
      (
      ) 

    ) 

[1] => Array 
    (
     [Pacient] => Array 
      (
       [name] => pablo Giani 
       [id] => 520178ed-d564-465c-93fd-498f8e7a58df 
      ) 

     [Appointment] => Array 
      (
      ) 

    ) 

)

ответ

0

Figuere это после попытки многих находок и Pr

$pacients =$this->Appointment->Pacient->find('list', array(
     'conditions' => array('User_id' => $foo) 
    )); 

I надеюсь, что это поможет другому небу, например, мне

Смежные вопросы