2014-03-25 57 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";} 
相关问题