Loading custom class in CakePHP3

血红的双手。 提交于 2020-01-17 02:51:04

问题


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.


回答1:


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

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



来源:https://stackoverflow.com/questions/39545579/loading-custom-class-in-cakephp3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!