0

I am trying to load a custom class in my CakePHP3 project, although I can't seem to find out what I am missing.

I have a folder src/Library with Config.php in it:

<?php

namespace App\Library;

/**
 * Class containing CONST values for important settings
 *
 * @version 1.0
 * @author berry
 */
class Config
{
    const UPLOAD_DIRECTORY = './upload/';
}

I put use App\Library\Config; in my PicturesController, which Visual Studio even recognizes as a valid class (I can access the const through intellisense)

Here is my controller:

<?php
namespace App\Controller;

use App\Controller\AppController;
use Cake\Filesystem\Folder;
use Cake\Filesystem\File;
use App\Library\Config;

/**
 * Pictures Controller
 *
 * @property \App\Model\Table\PicturesTable $Pictures
 */
class PicturesController extends AppController
{
    public function upload()
    {
        if($this->request->is('post'))
        {
            $oConfig = new Config();

            $oUploadDir = new Folder($oConfig::UPLOAD_DIRECTORY);

            debug($oUploadDir);

            $aFile = $this->request->data('submittedfile');
        }

    }

So despite my IDE even registering the class (and telling me I'm using it correctly) I get Class 'App\Library\Config' not found thrown in the browser.

Berry M.
  • 469
  • 1
  • 4
  • 17
  • Your class belongs in the vendor directory. There is a great explaination here. http://stackoverflow.com/questions/28518238/how-can-i-use-my-own-external-class-in-cakephp-3-0 –  Sep 17 '16 at 13:47
  • Is the Config.php file have correct permissions? – Derek Sep 18 '16 at 15:18
  • Well, I changed the foldername from Library to my name, and it worked. So either the Lirary folder didn't have the right permissions, or Library is already in use. – Berry M. Sep 19 '16 at 07:44
  • @BerryM. try providing decent answers to questions to gain rep instead of suggesting petty updates to existing good answers. (I note none of your answers have votes to date) Regards. – Rachel Gallen Oct 07 '16 at 16:55
  • @RachelGallen such criticism, while I admit is justified, does as far as I am aware not belong in a comment section. – Berry M. Oct 08 '16 at 11:48

1 Answers1

0

I changed the name from Library to Berry (My first name).

Apparently you can't call it Library. Probably used somewhere else in Cake.

Berry M.
  • 469
  • 1
  • 4
  • 17