2014-03-25 52 views
0

我有小問題,所以我需要一些幫助。也許它很容易,但我只需要一推......所以我withing一個控制器從一個控制器編輯2控制器(正確)

public function edit($id = null) { 
    if (!$this->TypologyPicture->exists($id)) { 
     throw new NotFoundException(__('Invalid typology picture')); 
    } 
    if ($this->request->is(array('post', 'put'))) { 
      if(empty($this->data['TypologyPicture']['pic_path']['name'])){ 
       unset($this->request->data['TypologyPicture']['pic_path']); 
       } 
     if ($this->TypologyPicture->save($this->request->data)) { 
      $this->Session->setFlash(__('The typology picture has been saved.')); 
      return $this->redirect(array('action' => 'index')); 
     } else { 
      $this->Session->setFlash(__('The typology picture could not be saved. Please, try again.')); 
     } 
    } else { 
     $options = array('conditions' => array('TypologyPicture.' . $this->TypologyPicture->primaryKey => $id)); 
     $this->request->data = $this->TypologyPicture->find('first', $options); 

     //$options1 = array('conditions' => array('Typology.id' => $id)); 
     $opt = array('conditions' => array('Typology.id' => $this->request->data['TypologyPicture']['typology_id'])); 
     $this->request->data = $this->Typology->find('first', $opt); 

    } 


    if (AuthComponent::user('role')==='admin' ||AuthComponent::user('role')==='superadmin'){ //if the user is admin or superadmin, show all on dropdown 
      $items = $this->Typology->TypologyItem->find('list'); 
     } else {// else if the user is author, show only item created by him. 
      $items = $this->Typology->TypologyItem->find('list', array('conditions' => array('TypologyItem.user_id' => AuthComponent::user('id'))));    
     } 
    $typologyCategories = $this->Typology->TypologyCategory->find('list'); 
    $typologyConditions = $this->Typology->TypologyCondition->find('list'); 
    $users = $this->Typology->TypologyUser->find('list'); 
    $this->set(compact('items', 'typologyCategories', 'typologyConditions', 'users')); 

    if (AuthComponent::user('role')==='admin' ||AuthComponent::user('role')==='superadmin'){ 
     $typologies = $this->TypologyPicture->ItemTypologyPicture->find('list'); 
    } else { 
     $typologies = $this->TypologyPicture->ItemTypologyPicture->find('list', array('conditions' => array('ItemTypologyPicture.user_id' => AuthComponent::user('id')))); 
     } 
    $this->set(compact('typologies')); 
} 

所以當你從接觸控制器看,我要訪問我想編輯和其旗下的圖片,是接觸存儲在contact_picture表。自己聯繫有像一個圖標或一個化身,並在聯繫圖片存儲畫廊。所以這裏的問題是,我得到所有的數據,因爲它應該,但聯繫人(頭像或圖標)的形象didesent顯示,路徑正確retrived但它只是顯示圖像。

所以我問的是,如果有另一種方式或簡單的方法,甚至更好的方式來做到這一點,我真的appruciate它......真的。

在此先感謝!

編輯:視圖部分:

<?php echo $this->Form->create('TypologyPicture', array('type'=>'file')); ?> 
     <legend><?php echo __('Edit Typology Picture'); ?></legend> 
    <?php 
    $dir = "/img/uploads/typology/images/"; 
     echo $this->Form->input('id'); ?> 

<?php echo $this->Form->input('Typology.item_id',array('empty'=>true)); ?> 
<?php echo $this->Form->input('Typology.title'); ?> 
<?php echo $this->Form->input('Typology.description');?> 
<?php echo $this->Form->input('Typology.thumbnail',array('type'=>'file')); ?> 
<?php echo $this->Form->input('Typology.typology_category_id',array('empty'=>true)); ?> 
<?php echo $this->Form->input('Typology.typology_condition_id',array('empty'=>true)); ?> 
<?php echo $this->Form->input('Typology.price',array('placeholder'=>'Price')); ?> 
<!-- Here is the second part of the update --> 
<?php echo $this->Form->input('pic_path', array('label'=>'Picture','type'=>'file')); 
     echo $this->Form->input('hiddenimage', array('type'=>'hidden','value'=> $this->Form->value('pic_path'))); 
     $Image = $this->Form->value('pic_path');  
      if(empty($Image) || $Image==NULL) 
        {$Image = "/img/uploads/noimg.jpg";} 
       else {$Image = $dir . $Image; } 
     echo $this->Html->image($Image,array('align'=>'absbottom','style'=>'max-height:100px')); 
    ?> 
<?php echo $this->Form->end(__('Submit')); ?> 

所以,當我做回顯到圖像它正確doesent顯示...如果我刪除像一個正常的編輯類型學模型的一部分,它顯示正常。 ..

+0

如果路徑被正確檢索,我還以爲它更可能是一個查看問題 - 你可以發佈你的視圖代碼?你有沒有檢查過,你可以使用返回的路徑導航到圖像? 就您檢索數據的方式而言,我認爲我們需要更多地瞭解您的模型,即。爲什麼你在$ this-> Typology-> find中找到使用Contact.id?我會盡管它會更像:Typology.contact_id如果聯繫人有很多類型學? – theotherdy

+0

@theotherdy這裏是正確的代碼......你怎麼看?我可能會誤認? – landi

+0

感謝@landi,以及Typology和TypologyPicture之間的關係?不確定我完全理解 - 你可以導航到$ Image – theotherdy

回答

0

嘗試從$ dir和$ Image中刪除img部分;

$dir = "/img/uploads/typology/images/"; 

應該

$dir = "uploads/typology/images/"; 

{$Image = "/img/uploads/noimg.jpg";} 

應該

{$Image = "uploads/noimg.jpg";} 
相關問題