2012-01-16 74 views
0

我的查詢只返回了我的library_id。我需要在我看來顯示標題。我怎樣才能獲得顯示的標題。 這裏是我的分成模式如何獲取更多字段

public $belongsTo = array(
     'Person' => array(
      'className' => 'Person', 
      'foreignKey' => 'person_id', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '' 
     ), 
     'Library' => array(
      'className' => 'Library', 
      'foreignKey' => 'library_id', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '' 
     ) 
    ); 

這裏是我的圖書館模型

class Library extends AppModel { 

    //The Associations below have been created with all possible keys, those that are not needed can be removed 

/** 
* hasMany associations 
* 
* @var array 
*/ 
    public $hasMany = array(
     'Share' => array(
      'className' => 'Share', 
      'foreignKey' => 'library_id', 
      'dependent' => false, 
      'conditions' => '', 
      'fields' => 'Title', 
      'order' => '', 
      'limit' => '', 
      'offset' => '', 
      'exclusive' => '', 
      'finderQuery' => '', 
      'counterQuery' => '' 
     ), 
     'Work' => array(
      'className' => 'Work', 
      'foreignKey' => 'library_id', 
      'dependent' => false, 
      'conditions' => '', 
      'fields' => '', 
      'order' => '', 
      'limit' => '', 
      'offset' => '', 
      'exclusive' => '', 
      'finderQuery' => '', 
      'counterQuery' => '' 
     ) 
    ); 

} 

這裏是控制我的add方法

public function add() { 
     if ($this->request->is('post')) { 
      $this->Share->create(); 
      if ($this->Share->save($this->request->data)) { 
       $this->Session->setFlash(__('The share has been saved')); 
       $this->redirect(array('action' => 'index')); 
      } else { 
       $this->Session->setFlash(__('The share could not be saved. Please, try again.')); 
      } 
     } 
     $people = $this->Share->Person->find('list'); 
     $libraries = $this->Share->Library->find('list'); 
     $this->set(compact('people', 'libraries')); 
    } 

這裏是我的看法

<div class="shares form"> 
<?php echo $this->Form->create('Share');?> 
    <fieldset> 
     <legend><?php echo __('Add Share'); ?></legend> 
    <?php 
     echo $this->Form->input('person_id'); 
    echo $this->Form->input('library_id'); 
     echo $this->Form->input('share'); 

    ?> 
    </fieldset> 
<?php echo $this->Form->end(__('Submit'));?> 
</div> 

回答

0

無所謂的問題首先我需要做的是

$ libraries = $ this-> Share-> Library-> find('list',array('fields'=>'Library.Title'));

在LibrariesController

感謝