Alimon Karim
Alimon Karim

Reputation: 4469

Cakephp2.0 missing component

I used a component name upload.php and save it in /app/controllers/components/ directory.

After that I used code in my controller like

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

After save that I find error that is missing component. I could not find any mistake.Can any body help me?

Upvotes: 0

Views: 697

Answers (1)

dhofstet
dhofstet

Reputation: 9964

You have placed the component in the wrong folder. In CakePHP 2.x, components are placed in app/Controller/Component. You also have to rename the component from upload.php to UploadComponent (and probably adapt the code to make it work with CakePHP 2.x).

Upvotes: 2

Related Questions