Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cakephp 从一个控制器编辑两个控制器(正确)_Cakephp_Cakephp 2.3_Cakephp Model - Fatal编程技术网

Cakephp 从一个控制器编辑两个控制器(正确)

Cakephp 从一个控制器编辑两个控制器(正确),cakephp,cakephp-2.3,cakephp-model,Cakephp,Cakephp 2.3,Cakephp Model,我有个小问题,所以我需要一些帮助。也许这很容易,但我只需要推一下。。。所以我有一个控制器 public function edit($id = null) { if (!$this->TypologyPicture->exists($id)) { throw new NotFoundException(__('Invalid typology picture')); } if ($this->request->is(array('p

我有个小问题,所以我需要一些帮助。也许这很容易,但我只需要推一下。。。所以我有一个控制器

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 controller中看到的,我希望访问要编辑的联系人及其存储在contact_picture表中的图片。联系人本身有一个图标或化身,联系人中的图片存储在图库中。所以这里的问题是,我得到了所有的数据,但联系人(化身,或图标)的图像没有显示,路径被正确检索,但它只是显示了图像

所以我想问的是,如果有其他的方法,或者简单的方法,或者更好的方法,我会非常感激它…真的

提前谢谢

编辑:视图零件:

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


所以当我回显图像时,它不会正确显示。。。如果我像普通编辑一样删除类型学模型部分,它将显示普通…

尝试从$dir和$Image中删除img部分

$dir = "/img/uploads/typology/images/"; 
应该是

$dir = "uploads/typology/images/"; 
{$Image = "uploads/noimg.jpg";}

应该是

$dir = "uploads/typology/images/"; 
{$Image = "uploads/noimg.jpg";}

如果路径被正确检索,我会认为这更可能是一个视图问题-你能发布你的视图代码吗?是否已检查是否可以使用返回的路径导航到图像?就您检索数据的方式而言,我认为我们需要更多地了解您的模型,即:为什么您要在$this->Typology->find中使用Contact.id进行查找……我认为这更像是:Typology.Contact\u id如果Contact有许多类型?@下面是正确的代码。。。你怎么认为?我可能弄错了???谢谢@landi,还有类型学和类型结构之间的关系?不确定我是否完全理解-您可以导航到中的路径吗$Image@theotherdy关系是类型学属于类型学,类型学有许多类型学。至于$image,如果我删除我添加的代码,或者如果我放入$opt=array('conditions'=>array('Typology.id'=>this->request->data['TypologyPicture']['Typology\u id']),那么是的$此->请求->数据['Typology']=$this->Typology->find('first',$opt);图像显示,但相关数据丢失。。