Question

i have small problem so i need some help. maybe its very easy but i just need a push... so i am withing one controller

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'));
}

so as you see from contact controller i want to access the contact that i want to edit and its its pictures that are stored in contact_picture table. contact by itself has like an icon or an avatar, and in contact picture are stored the gallery. so here the problem is that i get all the data as it supposed to, but the image of the contact (avatar, or icon) doesent dispay, the path is retrived correctly but it just doesent display the image.

So what im asking is that if there is another way or easy way or even better way to do that i would really appruciate it...really.

Thanks in advance!

EDIT: The View Part:

<?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')); ?>

So when i do echo to the image it doesent display correctly... if i remove the typology model part like a normal edit, it displays normal...

Was it helpful?

Solution

try by removing the img part from $dir and $Image;

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

should be

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

and

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

should be

{$Image = "uploads/noimg.jpg";}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top