2013-12-10 70 views
0

我使用了一個組件名upload.php並將它保存在/ app/controllers/components /目錄下。Cakephp2.0缺失組件

之後,我使用的代碼在我的控制器一樣

<?php 
App::uses('AppController', 'Controller'); 

App::uses('BarcodeHelper','Vendor'); 
/** 
* OesUsers Controller 
* 
* @property OesUser $OesUser 
*/ 

class OesUsersController extends AppController { 

    var $name = 'Images'; 
    var $helpers = array('Html', 'Form'); 
    var $components = array('upload'); 

function upload() { 

if (empty($this->data)) { 
    $this->render(); 
} else { 
    $this->cleanUpFields(); 

    // set the upload destination folder 
    $destination = realpath('../../app/webroot/img/uploads/') . '/'; 

    // grab the file 
    $file = $this->data['Image']['filedata']; 

    // upload the image using the upload component 
    $result = $this->Upload->upload($file, $destination, null, array('type' => 'resizecrop', 'size' => array('400', '300'), 'output' => 'jpg')); 

    if (!$result){ 
     $this->data['Image']['filedata'] = $this->Upload->result; 
    } else { 
     // display error 
     $errors = $this->Upload->errors; 

     // piece together errors 
     if(is_array($errors)){ $errors = implode("<br />",$errors); } 

     $this->Session->setFlash($errors); 
     $this->redirect('/images/upload'); 
     exit(); 
    } 
    if ($this->Image->save($this->data)) { 
     $this->Session->setFlash('Image has been added.'); 
     $this->redirect('/images/index'); 
    } else { 
     $this->Session->setFlash('Please correct errors below.'); 
     unlink($destination.$this->Upload->result); 
    } 
} 
} 

保存我發現缺少組件錯誤後。我找不到任何錯誤。任何身體都可以幫助我嗎?

回答

2

您已將組件放在錯誤的文件夾中。在CakePHP 2.x中,組件位於app/Controller/Component。您還必須將組件從upload.php重命名爲UploadComponent(並可能調整代碼以使其與CakePHP 2.x協同工作)。

+0

已經解決了,非常感謝。 –